diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | include/ruby/encoding.h | 3 | ||||
-rw-r--r-- | parse.y | 9 | ||||
-rw-r--r-- | string.c | 20 |
4 files changed, 37 insertions, 3 deletions
@@ -1,3 +1,11 @@ +Tue Jan 22 04:40:28 2008 Yukihiro Matsumoto <matz@ruby-lang.org> + + * parse.y (rb_intern3): do not call rb_enc_mbclen() if *m is + ASCII. [ruby-talk:287225] + + * string.c (rb_str_each_line): use rb_enc_is_newline() to gain + performance if the record separator ($/) is not modified. + Tue Jan 22 01:15:51 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com> * ChangeLog: format-time-string under C locale. [ruby-dev:33261] diff --git a/include/ruby/encoding.h b/include/ruby/encoding.h index b914913b4d..fad89a6da8 100644 --- a/include/ruby/encoding.h +++ b/include/ruby/encoding.h @@ -133,6 +133,9 @@ int rb_enc_codelen(int code, rb_encoding *enc); #define rb_enc_left_char_head(s,p,enc) (char *)onigenc_get_left_adjust_char_head(enc,(UChar*)(s),(UChar*)(p)) #define rb_enc_right_char_head(s,p,enc) (char *)onigenc_get_right_adjust_char_head(enc,(UChar*)(s),(UChar*)(p)) +/* ptr, ptr, encoding -> newline_or_not */ +#define rb_enc_is_newline(p,end,enc) ONIGENC_IS_MBC_NEWLINE(enc,p,end) + #define rb_enc_isctype(c,t,enc) ONIGENC_IS_CODE_CTYPE(enc,c,t) #define rb_enc_isascii(c,enc) ONIGENC_IS_CODE_ASCII(c) #define rb_enc_isalpha(c,enc) ONIGENC_IS_CODE_ALPHA(enc,c) @@ -8966,8 +8966,13 @@ rb_intern3(const char *name, long len, rb_encoding *enc) mb = 0; if (!rb_enc_isdigit(*m, enc)) { while (m <= name + last && is_identchar(m, e, enc)) { - if (!ISASCII(*m)) mb = 1; - m += rb_enc_mbclen(m, e, enc); + if (ISASCII(*m)) { + m++; + } + else { + mb = 1; + m += rb_enc_mbclen(m, e, enc); + } } } if (m - name < len) id = ID_JUNK; @@ -4468,6 +4468,7 @@ rb_str_each_line(int argc, VALUE *argv, VALUE str) char *ptr = p; long len = RSTRING_LEN(str), rslen; VALUE line; + int n; if (rb_scan_args(argc, argv, "01", &rs) == 0) { rs = rb_rs; @@ -4480,6 +4481,22 @@ rb_str_each_line(int argc, VALUE *argv, VALUE str) } StringValue(rs); enc = rb_enc_check(str, rs); + if (rs == rb_default_rs) { + while (p < pend) { + n = rb_enc_mbclen(p, pend, enc); + if (rb_enc_is_newline(p, pend, enc)) { + line = rb_str_new5(str, s, p - s + n); + OBJ_INFECT(line, str); + rb_enc_copy(line, str); + rb_yield(line); + str_mod_check(str, ptr, len); + s = p + n; + } + p += n; + } + goto finish; + } + rslen = RSTRING_LEN(rs); if (rslen == 0) { newline = '\n'; @@ -4490,8 +4507,8 @@ rb_str_each_line(int argc, VALUE *argv, VALUE str) while (p < pend) { int c = rb_enc_codepoint(p, pend, enc); - int n = rb_enc_codelen(c, enc); + n = rb_enc_codelen(c, enc); if (rslen == 0 && c == newline) { while (p < pend && rb_enc_codepoint(p, pend, enc) == newline) { p += n; @@ -4510,6 +4527,7 @@ rb_str_each_line(int argc, VALUE *argv, VALUE str) p += n; } + finish: if (s != pend) { if (p > pend) p = pend; line = rb_str_new5(str, s, p - s); |