Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

* re.c (rb_memsearch_ss): performance improvement by using memmem(3) if

  possible. [ruby-dev:45530] [Feature #6311]

* configure.in: check existence of memmem(3) and that it is not broken.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37634 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
commit c5b19cf01cd15e0d9d8e2847ba746a5f361841df 1 parent d24e2d7
Masaki Matsushita Glasssaga authored

Showing 3 changed files with 56 additions and 0 deletions. Show diff stats Hide diff stats

  1. +7 0 ChangeLog
  2. +36 0 configure.in
  3. +13 0 re.c
7 ChangeLog
... ... @@ -1,3 +1,10 @@
  1 +Tue Nov 13 11:03:47 2012 Masaki Matsushita <glass.saga@gmail.com>
  2 +
  3 + * re.c (rb_memsearch_ss): performance improvement by using memmem(3) if
  4 + possible. [ruby-dev:45530] [Feature #6311]
  5 +
  6 + * configure.in: check existence of memmem(3) and that it is not broken.
  7 +
1 8 Tue Nov 13 06:50:02 2012 Aaron Patterson <aaron@tenderlovemaking.com>
2 9
3 10 * probes.d: add DTrace probe declarations. [ruby-core:27448]
36 configure.in
@@ -2900,6 +2900,42 @@ if test "${universal_binary-no}" = yes ; then
2900 2900 ])])
2901 2901 fi
2902 2902
  2903 +AC_CHECK_FUNC(memmem, [
  2904 + AC_CACHE_CHECK(for broken memmem, rb_cv_broken_memmem, [
  2905 + AC_TRY_RUN([
  2906 +#include <string.h>
  2907 +
  2908 +int
  2909 +main()
  2910 +{
  2911 + char *str = "hogefugafoobar";
  2912 + char *rs = "foo";
  2913 + char *empty = "";
  2914 + char *p;
  2915 +
  2916 + p = memmem(str, strlen(str), rs, strlen(rs));
  2917 + if (p == str+8) {
  2918 + p = memmem(str, strlen(str), empty, strlen(empty));
  2919 + if (p == str)
  2920 + return 0;
  2921 + else
  2922 + return 1;
  2923 + }
  2924 + else {
  2925 + return 1;
  2926 + }
  2927 +}
  2928 + ],
  2929 + rb_cv_broken_memmem=no,
  2930 + rb_cv_broken_memmem=yes,
  2931 + rb_cv_broken_memmem=yes)
  2932 + ])
  2933 + if test "$rb_cv_broken_memmem" = no; then
  2934 + AC_DEFINE(HAVE_MEMMEM, 1)
  2935 + fi
  2936 +])
  2937 +
  2938 +
2903 2939 CPPFLAGS="$CPPFLAGS "'$(DEFS)'
2904 2940 test -z "$CPPFLAGS" || CPPFLAGS="$CPPFLAGS "; CPPFLAGS="$CPPFLAGS"'${cppflags}'
2905 2941 if test -n "${cflags+set}"; then
13 re.c
@@ -97,6 +97,18 @@ rb_memcmp(const void *p1, const void *p2, long len)
97 97 return memcmp(p1, p2, len);
98 98 }
99 99
  100 +#ifdef HAVE_MEMMEM
  101 +static inline long
  102 +rb_memsearch_ss(const unsigned char *xs, long m, const unsigned char *ys, long n)
  103 +{
  104 + const unsigned char *y;
  105 +
  106 + if (y = memmem(ys, n, xs, m))
  107 + return y - ys;
  108 + else
  109 + return -1;
  110 +}
  111 +#else
100 112 static inline long
101 113 rb_memsearch_ss(const unsigned char *xs, long m, const unsigned char *ys, long n)
102 114 {
@@ -132,6 +144,7 @@ rb_memsearch_ss(const unsigned char *xs, long m, const unsigned char *ys, long n
132 144 }
133 145 return y - ys - m;
134 146 }
  147 +#endif
135 148
136 149 static inline long
137 150 rb_memsearch_qs(const unsigned char *xs, long m, const unsigned char *ys, long n)

0 comments on commit c5b19cf

Please sign in to comment.
Something went wrong with that request. Please try again.