ruby-changes:3674
From: ko1@a...
Date: Tue, 22 Jan 2008 04:47:48 +0900 (JST)
Subject: [ruby-changes:3674] matz - Ruby:r15163 (trunk): * parse.y (rb_intern3): do not call rb_enc_mbclen() if *m is
matz 2008-01-22 04:47:26 +0900 (Tue, 22 Jan 2008)
New Revision: 15163
Modified files:
trunk/ChangeLog
trunk/include/ruby/encoding.h
trunk/parse.y
trunk/string.c
Log:
* 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.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/string.c?r1=15163&r2=15162&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/parse.y?r1=15163&r2=15162&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15163&r2=15162&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/include/ruby/encoding.h?r1=15163&r2=15162&diff_format=u
Index: include/ruby/encoding.h
===================================================================
--- include/ruby/encoding.h (revision 15162)
+++ include/ruby/encoding.h (revision 15163)
@@ -133,6 +133,9 @@
#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)
Index: ChangeLog
===================================================================
--- ChangeLog (revision 15162)
+++ ChangeLog (revision 15163)
@@ -1,3 +1,11 @@
+Tue Jan 22 04:40:28 2008 Yukihiro Matsumoto <matz@r...>
+
+ * 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@m...>
* ChangeLog: format-time-string under C locale. [ruby-dev:33261]
Index: string.c
===================================================================
--- string.c (revision 15162)
+++ string.c (revision 15163)
@@ -4468,6 +4468,7 @@
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 @@
}
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 @@
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 @@
p += n;
}
+ finish:
if (s != pend) {
if (p > pend) p = pend;
line = rb_str_new5(str, s, p - s);
Index: parse.y
===================================================================
--- parse.y (revision 15162)
+++ parse.y (revision 15163)
@@ -8966,8 +8966,13 @@
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;
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/