mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@15163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7760f3c462
commit
56be84e293
4 changed files with 37 additions and 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]
|
||||
|
|
|
@ -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)
|
||||
|
|
9
parse.y
9
parse.y
|
@ -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;
|
||||
|
|
20
string.c
20
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);
|
||||
|
|
Loading…
Reference in a new issue