summaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-21 19:47:26 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-21 19:47:26 +0000
commit070760eda165135fa6d8f4a19890043a239a3199 (patch)
tree2ae0c620f08f299d6b7b0c775982e165e82b3f7f /string.c
parent306fbb6a0c2af726f7a30585c59f8b4c14878437 (diff)
downloadruby-070760eda165135fa6d8f4a19890043a239a3199.tar.gz
ruby-070760eda165135fa6d8f4a19890043a239a3199.tar.xz
ruby-070760eda165135fa6d8f4a19890043a239a3199.zip
* 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. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/string.c b/string.c
index 4d3d83792..3865dbcd7 100644
--- a/string.c
+++ b/string.c
@@ -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);