diff --git a/ChangeLog b/ChangeLog index bf21d8d178..babc64953b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Nov 8 21:57:59 2012 Masaki Matsushita + + * re.c (rb_memsearch): performance improvement by using memchr(). + [ruby-dev:45397] [Feature #6173] + Thu Nov 8 19:02:50 2012 NARUSE, Yui * lib/net/protocol.rb (Net::InternetMessageIO#each_crlf_line): diff --git a/re.c b/re.c index 70e3c3fe34..ea11f1c015 100644 --- a/re.c +++ b/re.c @@ -220,12 +220,12 @@ rb_memsearch(const void *x0, long m, const void *y0, long n, rb_encoding *enc) return 0; } else if (m == 1) { - const unsigned char *ys = y, *ye = ys + n; - for (; y < ye; ++y) { - if (*x == *y) - return y - ys; - } - return -1; + const unsigned char *ys; + + if (ys = memchr(y, *x, n)) + return ys - y; + else + return -1; } else if (m <= SIZEOF_VALUE) { return rb_memsearch_ss(x0, m, y0, n);