ruby-changes:30250
From: akr <ko1@a...>
Date: Thu, 1 Aug 2013 07:39:04 +0900 (JST)
Subject: [ruby-changes:30250] akr:r42302 (trunk): * bignum.c (big2str_orig): Use temporary buffer when trim mode.
akr 2013-08-01 07:38:53 +0900 (Thu, 01 Aug 2013) New Revision: 42302 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42302 Log: * bignum.c (big2str_orig): Use temporary buffer when trim mode. Modified files: trunk/ChangeLog trunk/bignum.c Index: ChangeLog =================================================================== --- ChangeLog (revision 42301) +++ ChangeLog (revision 42302) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Aug 1 07:36:27 2013 Tanaka Akira <akr@f...> + + * bignum.c (big2str_orig): Use temporary buffer when trim mode. + Thu Aug 1 06:28:48 2013 Tanaka Akira <akr@f...> * bignum.c (big2str_orig): Simplified because RBIGNUM_LEN(x) <= 2 now. Index: bignum.c =================================================================== --- bignum.c (revision 42301) +++ bignum.c (revision 42302) @@ -4224,13 +4224,23 @@ static size_t https://github.com/ruby/ruby/blob/trunk/bignum.c#L4224 big2str_orig(struct big2str_struct *b2s, VALUE x, char* ptr, size_t len, int trim) { long i = RBIGNUM_LEN(x); - size_t j = len; + size_t j; int k; BDIGIT* ds = BDIGITS(x); BDIGIT_DBL num; + char buf[SIZEOF_BDIGIT_DBL*CHAR_BIT], *p; assert(i <= 2); + if (trim) { + p = buf; + j = sizeof(buf); + } + else { + p = ptr; + j = len; + } + num = 0; if (0 < i) num = ds[0]; @@ -4239,15 +4249,16 @@ big2str_orig(struct big2str_struct *b2s, https://github.com/ruby/ruby/blob/trunk/bignum.c#L4249 k = b2s->hbase2_numdigits; while (k--) { - ptr[--j] = ruby_digitmap[num % b2s->base]; + p[--j] = ruby_digitmap[num % b2s->base]; num /= b2s->base; if (j <= 0) break; if (trim && num == 0) break; } if (trim) { - while (j < len && ptr[j] == '0') j++; - MEMMOVE(ptr, ptr + j, char, len - j); - len -= j; + while (j < sizeof(buf) && p[j] == '0') j++; + assert(sizeof(buf)-j <= len); + MEMCPY(ptr, p + j, char, sizeof(buf) - j); + len = sizeof(buf) - j; } return len; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/