[前][次][番号順一覧][スレッド一覧]

ruby-changes:29846

From: glass <ko1@a...>
Date: Wed, 10 Jul 2013 22:35:49 +0900 (JST)
Subject: [ruby-changes:29846] glass:r41898 (trunk): * string.c (rb_str_index): cache single byte flag and some

glass	2013-07-10 22:35:36 +0900 (Wed, 10 Jul 2013)

  New Revision: 41898

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41898

  Log:
    * string.c (rb_str_index): cache single byte flag and some
      cosmetic changes.

  Modified files:
    trunk/ChangeLog
    trunk/string.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41897)
+++ ChangeLog	(revision 41898)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jul 10 22:31:25 2013  Masaki Matsushita  <glass.saga@g...>
+
+	* string.c (rb_str_index): cache single byte flag and some
+	  cosmetic changes.
+
 Wed Jul 10 22:03:27 2013  Tanaka Akira  <akr@f...>
 
 	* bignum.c (bary_2comp): Don't use bary_plus_one.
Index: string.c
===================================================================
--- string.c	(revision 41897)
+++ string.c	(revision 41898)
@@ -2469,26 +2469,26 @@ rb_str_casecmp(VALUE str1, VALUE str2) https://github.com/ruby/ruby/blob/trunk/string.c#L2469
 static long
 rb_str_index(VALUE str, VALUE sub, long offset)
 {
-    long pos;
     char *s, *sptr, *e;
-    long len, slen;
+    long pos, len, slen;
+    int single_byte = single_byte_optimizable(str);
     rb_encoding *enc;
 
     enc = rb_enc_check(str, sub);
-    if (is_broken_string(sub)) {
-	return -1;
-    }
-    len = str_strlen(str, enc);
+    if (is_broken_string(sub)) return -1;
+
+    len = single_byte ? RSTRING_LEN(str) : str_strlen(str, enc);
     slen = str_strlen(sub, enc);
     if (offset < 0) {
 	offset += len;
 	if (offset < 0) return -1;
     }
     if (len - offset < slen) return -1;
+
     s = RSTRING_PTR(str);
-    e = s + RSTRING_LEN(str);
+    e = RSTRING_END(str);
     if (offset) {
-	offset = str_offset(s, RSTRING_END(str), offset, enc, single_byte_optimizable(str));
+	offset = str_offset(s, e, offset, enc, single_byte);
 	s += offset;
     }
     if (slen == 0) return offset;
@@ -2502,7 +2502,8 @@ rb_str_index(VALUE str, VALUE sub, long https://github.com/ruby/ruby/blob/trunk/string.c#L2502
 	if (pos < 0) return pos;
 	t = rb_enc_right_char_head(s, s+pos, e, enc);
 	if (t == s + pos) break;
-	if ((len -= t - s) <= 0) return -1;
+	len -= t - s;
+	if (len <= 0) return -1;
 	offset += t - s;
 	s = t;
     }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]