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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37793 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
knu 2012-11-22 05:23:12 +00:00
Родитель 9cbaeed6ed
Коммит 61e21e82ad
3 изменённых файлов: 16 добавлений и 0 удалений

Просмотреть файл

@ -1,3 +1,9 @@
Thu Nov 22 14:14:36 2012 Akinori MUSHA <knu@iDaemons.org>
* 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@iDaemons.org> Thu Nov 22 12:52:19 2012 Akinori MUSHA <knu@iDaemons.org>
* test/ruby/test_string.rb (TestString#test_index): Add some * test/ruby/test_string.rb (TestString#test_index): Add some

3
re.c
Просмотреть файл

@ -126,6 +126,9 @@ rb_memsearch_ss(const unsigned char *xs, long m, const unsigned char *ys, long n
if (m > SIZEOF_VALUE) if (m > SIZEOF_VALUE)
rb_bug("!!too long pattern string!!"); rb_bug("!!too long pattern string!!");
if (!(y = memchr(y, *x, n - m + 1)))
return -1;
/* Prepare hash value */ /* Prepare hash value */
for (hx = *x++, hy = *y++; x < xe; ++x, ++y) { for (hx = *x++, hy = *y++; x < xe; ++x, ++y) {
hx <<= CHAR_BIT; hx <<= CHAR_BIT;

Просмотреть файл

@ -837,6 +837,13 @@ class TestString < Test::Unit::TestCase
assert_equal(0, S("hello").index(S(""))) assert_equal(0, S("hello").index(S("")))
assert_equal(0, S("hello").index(//)) 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 o = Object.new
def o.to_str; "bar"; end def o.to_str; "bar"; end
assert_equal(3, "foobarbarbaz".index(o)) assert_equal(3, "foobarbarbaz".index(o))