ruby-changes:11554
From: nobu <ko1@a...>
Date: Mon, 13 Apr 2009 17:22:05 +0900 (JST)
Subject: [ruby-changes:11554] Ruby:r23188 (trunk): * sprintf.c (rb_str_format): scan coderange incrementally.
nobu 2009-04-13 17:21:41 +0900 (Mon, 13 Apr 2009) New Revision: 23188 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23188 Log: * sprintf.c (rb_str_format): scan coderange incrementally. Modified files: trunk/ChangeLog trunk/sprintf.c Index: ChangeLog =================================================================== --- ChangeLog (revision 23187) +++ ChangeLog (revision 23188) @@ -1,3 +1,7 @@ +Mon Apr 13 17:21:40 2009 Nobuyoshi Nakada <nobu@r...> + + * sprintf.c (rb_str_format): scan coderange incrementally. + Mon Apr 13 11:35:55 2009 NARUSE, Yui <naruse@r...> * sprintf.c (rb_str_format): optimize previous commit. Index: sprintf.c =================================================================== --- sprintf.c (revision 23187) +++ sprintf.c (revision 23188) @@ -83,10 +83,12 @@ #define FPREC0 128 #define CHECK(l) do {\ + int cr = ENC_CODERANGE(result);\ while (blen + (l) >= bsiz) {\ bsiz*=2;\ }\ rb_str_resize(result, bsiz);\ + ENC_CODERANGE_SET(result, cr);\ buf = RSTRING_PTR(result);\ } while (0) @@ -431,6 +433,8 @@ int blen, bsiz; VALUE result; + long scanned = 0; + int coderange = ENC_CODERANGE_7BIT; int width, prec, flags = FNONE; int nextarg = 1; int posarg = 0; @@ -469,6 +473,7 @@ rb_enc_copy(result, fmt); buf = RSTRING_PTR(result); memset(buf, 0, bsiz); + ENC_CODERANGE_SET(result, coderange); for (; p < end; p++) { const char *t; @@ -661,6 +666,13 @@ if (OBJ_TAINTED(str)) tainted = 1; len = RSTRING_LEN(str); rb_str_set_len(result, blen); + if (coderange != ENC_CODERANGE_BROKEN && scanned < blen) { + int cr = coderange; + scanned = rb_str_coderange_scan_restartable(buf+scanned, buf+blen, enc, &cr); + ENC_CODERANGE_SET(result, + (cr == ENC_CODERANGE_UNKNOWN ? + ENC_CODERANGE_BROKEN : (coderange = cr))); + } enc = rb_enc_check(result, str); if (flags&(FPREC|FWIDTH)) { slen = rb_enc_strlen(RSTRING_PTR(str),RSTRING_END(str),enc); @@ -1043,6 +1055,10 @@ if (RTEST(ruby_debug)) rb_raise(rb_eArgError, "%s", mesg); if (RTEST(ruby_verbose)) rb_warn("%s", mesg); } + if (scanned < blen) { + rb_str_coderange_scan_restartable(buf+scanned, buf+blen, enc, &coderange); + ENC_CODERANGE_SET(result, coderange); + } rb_str_resize(result, blen); if (tainted) OBJ_TAINT(result); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/