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

ruby-changes:25736

From: knu <ko1@a...>
Date: Thu, 22 Nov 2012 14:23:23 +0900 (JST)
Subject: [ruby-changes:25736] knu:r37793 (trunk): Apply performance improvement to short byte array search.

knu	2012-11-22 14:23:12 +0900 (Thu, 22 Nov 2012)

  New Revision: 37793

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

  Log:
    Apply performance improvement to short byte array search.
    
    * re.c (rb_memsearch_ss): Apply performance improvement to short
      byte array search for platforms without memmem(3).
      [Feature #6311] [ruby-dev:45530]

  Modified files:
    trunk/ChangeLog
    trunk/re.c
    trunk/test/ruby/test_string.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37792)
+++ ChangeLog	(revision 37793)
@@ -1,3 +1,9 @@
+Thu Nov 22 14:14:36 2012  Akinori MUSHA  <knu@i...>
+
+	* re.c (rb_memsearch_ss): Apply performance improvement to short
+	  byte array search for platforms without memmem(3).
+	  [Feature #6311] [ruby-dev:45530]
+
 Thu Nov 22 12:52:19 2012  Akinori MUSHA  <knu@i...>
 
 	* test/ruby/test_string.rb (TestString#test_index): Add some
Index: re.c
===================================================================
--- re.c	(revision 37792)
+++ re.c	(revision 37793)
@@ -126,6 +126,9 @@
     if (m > SIZEOF_VALUE)
 	rb_bug("!!too long pattern string!!");
 
+    if (!(y = memchr(y, *x, n - m + 1)))
+	return -1;
+
     /* Prepare hash value */
     for (hx = *x++, hy = *y++; x < xe; ++x, ++y) {
 	hx <<= CHAR_BIT;
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb	(revision 37792)
+++ test/ruby/test_string.rb	(revision 37793)
@@ -837,6 +837,13 @@
     assert_equal(0, S("hello").index(S("")))
     assert_equal(0, S("hello").index(//))
 
+    s = S("long") * 1000 << "x"
+    assert_nil(s.index(S("y")))
+    assert_equal(4 * 1000, s.index(S("x")))
+    s << "yx"
+    assert_equal(4 * 1000, s.index(S("x")))
+    assert_equal(4 * 1000, s.index(S("xyx")))
+
     o = Object.new
     def o.to_str; "bar"; end
     assert_equal(3, "foobarbarbaz".index(o))

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

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