[macruby-changes] [5181] MacRuby/trunk/string.c

source_changes at macosforge.org source_changes at macosforge.org
Mon Jan 17 18:08:40 PST 2011


Revision: 5181
          http://trac.macosforge.org/projects/ruby/changeset/5181
Author:   lsansonetti at apple.com
Date:     2011-01-17 18:08:35 -0800 (Mon, 17 Jan 2011)
Log Message:
-----------
String#{each_line,lines} should be faster with UTF-8 multibyte strings

Modified Paths:
--------------
    MacRuby/trunk/string.c

Modified: MacRuby/trunk/string.c
===================================================================
--- MacRuby/trunk/string.c	2011-01-18 01:55:01 UTC (rev 5180)
+++ MacRuby/trunk/string.c	2011-01-18 02:08:35 UTC (rev 5181)
@@ -4681,13 +4681,18 @@
 	paragraph = true;
     }
 
-    const long len = str_length(RSTR(str));
+    character_boundaries_cache_t local_cache;
+    reset_character_boundaries_cache(&local_cache);
+
+    const long len = str_length_with_cache(RSTR(str), &local_cache);
     const bool tainted = OBJ_TAINTED(str);
 
     long pos = 0;
-    do {
-	long off = str_index_for_string(RSTR(str), rs_str, pos, -1, false);
+    while (true) {
+	long off = str_index_for_string_with_cache(RSTR(str), rs_str, pos, -1,
+		false, &local_cache);
 	if (paragraph && off >= 0) {
+	    // XXX this is slow if str is UTF-8 multibyte.
 	    int i;
 	    for (i = off + 1; i < len; i++) {
 		UChar c = str_get_uchar(RSTR(str), i);
@@ -4709,7 +4714,8 @@
 	    substr_len = off - pos + 1;
 	}
 
-	VALUE substr = rstr_substr(str, pos, substr_len);
+	VALUE substr = rstr_substr_with_cache(str, pos, substr_len,
+		&local_cache);
 	if (tainted) {
 	    OBJ_TAINT(substr);
 	}
@@ -4721,7 +4727,6 @@
 	}
 	pos = off + 1;
     }
-    while (true);
 
     return str;
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20110117/7f35c319/attachment.html>


More information about the macruby-changes mailing list