ruby-changes:33569
From: naruse <ko1@a...>
Date: Mon, 21 Apr 2014 19:15:25 +0900 (JST)
Subject: [ruby-changes:33569] naruse:r45650 (trunk): * string.c (coderange_scan): remove useless condtion `p < e` after
naruse 2014-04-21 19:15:20 +0900 (Mon, 21 Apr 2014) New Revision: 45650 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45650 Log: * string.c (coderange_scan): remove useless condtion `p < e` after search_nonascii. * string.c (rb_str_coderange_scan_restartable): ditto. Modified files: trunk/ChangeLog trunk/string.c Index: ChangeLog =================================================================== --- ChangeLog (revision 45649) +++ ChangeLog (revision 45650) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Apr 21 19:02:44 2014 NARUSE, Yui <naruse@r...> + + * string.c (coderange_scan): remove useless condtion `p < e` after + search_nonascii. + + * string.c (rb_str_coderange_scan_restartable): ditto. + Mon Apr 21 18:55:21 2014 NARUSE, Yui <naruse@r...> * ext/-test-/string/coderange.c: add Bug::String.new#coderange_scan Index: string.c =================================================================== --- string.c (revision 45649) +++ string.c (revision 45650) @@ -312,32 +312,22 @@ coderange_scan(const char *p, long len, https://github.com/ruby/ruby/blob/trunk/string.c#L312 if (rb_enc_asciicompat(enc)) { p = search_nonascii(p, e); - if (!p) { - return ENC_CODERANGE_7BIT; - } - while (p < e) { + if (!p) return ENC_CODERANGE_7BIT; + for (;;) { int ret = rb_enc_precise_mbclen(p, e, enc); - if (!MBCLEN_CHARFOUND_P(ret)) { - return ENC_CODERANGE_BROKEN; - } + if (!MBCLEN_CHARFOUND_P(ret)) return ENC_CODERANGE_BROKEN; p += MBCLEN_CHARFOUND_LEN(ret); - if (p < e) { - p = search_nonascii(p, e); - if (!p) { - return ENC_CODERANGE_VALID; - } - } + if (p == e) break; + p = search_nonascii(p, e); + if (!p) break; } - return ENC_CODERANGE_VALID; } - - while (p < e) { - int ret = rb_enc_precise_mbclen(p, e, enc); - - if (!MBCLEN_CHARFOUND_P(ret)) { - return ENC_CODERANGE_BROKEN; + else { + while (p < e) { + int ret = rb_enc_precise_mbclen(p, e, enc); + if (!MBCLEN_CHARFOUND_P(ret)) return ENC_CODERANGE_BROKEN; + p += MBCLEN_CHARFOUND_LEN(ret); } - p += MBCLEN_CHARFOUND_LEN(ret); } return ENC_CODERANGE_VALID; } @@ -362,23 +352,17 @@ rb_str_coderange_scan_restartable(const https://github.com/ruby/ruby/blob/trunk/string.c#L352 if (*cr != ENC_CODERANGE_VALID) *cr = ENC_CODERANGE_7BIT; return e - s; } - while (p < e) { + for (;;) { int ret = rb_enc_precise_mbclen(p, e, enc); if (!MBCLEN_CHARFOUND_P(ret)) { *cr = MBCLEN_INVALID_P(ret) ? ENC_CODERANGE_BROKEN: ENC_CODERANGE_UNKNOWN; return p - s; } p += MBCLEN_CHARFOUND_LEN(ret); - if (p < e) { - p = search_nonascii(p, e); - if (!p) { - *cr = ENC_CODERANGE_VALID; - return e - s; - } - } + if (p == e) break; + p = search_nonascii(p, e); + if (!p) break; } - *cr = ENC_CODERANGE_VALID; - return p - s; } else { while (p < e) { @@ -389,9 +373,9 @@ rb_str_coderange_scan_restartable(const https://github.com/ruby/ruby/blob/trunk/string.c#L373 } p += MBCLEN_CHARFOUND_LEN(ret); } - *cr = ENC_CODERANGE_VALID; - return p - s; } + *cr = ENC_CODERANGE_VALID; + return e - s; } static inline void -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/