This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Use memmem() if available on the platform for Perl_ninstr()
authorKarl Williamson <khw@cpan.org>
Wed, 11 May 2016 04:17:22 +0000 (22:17 -0600)
committerKarl Williamson <khw@cpan.org>
Fri, 13 May 2016 02:24:55 +0000 (20:24 -0600)
embed.fnc
embed.h
proto.h
util.c
util.h

index da809ef..bf3b8c5 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -1093,8 +1093,13 @@ Apd      |SV*    |vstringify     |NN SV *vs
 Apd    |int    |vcmp           |NN SV *lhv|NN SV *rhv
 : Used in pp_hot.c and pp_sys.c
 p      |PerlIO*|nextargv       |NN GV* gv|bool nomagicopen
+#ifdef HAS_MEMMEM
+AdnopP |char*  |ninstr         |NN const char* big|NN const char* bigend \
+                               |NN const char* little|NN const char* lend
+#else
 AdnpP  |char*  |ninstr         |NN const char* big|NN const char* bigend \
                                |NN const char* little|NN const char* lend
+#endif
 Apd    |void   |op_free        |NULLOK OP* arg
 Mp     |OP*    |op_unscope     |NULLOK OP* o
 #ifdef PERL_CORE
diff --git a/embed.h b/embed.h
index 6028a3d..6071c31 100644 (file)
--- a/embed.h
+++ b/embed.h
 #define new_numeric(a)         Perl_new_numeric(aTHX_ a)
 #define new_stackinfo(a,b)     Perl_new_stackinfo(aTHX_ a,b)
 #define new_version(a)         Perl_new_version(aTHX_ a)
-#define ninstr                 Perl_ninstr
 #define nothreadhook()         Perl_nothreadhook(aTHX)
 #define op_append_elem(a,b,c)  Perl_op_append_elem(aTHX_ a,b,c)
 #define op_append_list(a,b,c)  Perl_op_append_list(aTHX_ a,b,c)
 #define whichsig_pvn(a,b)      Perl_whichsig_pvn(aTHX_ a,b)
 #define whichsig_sv(a)         Perl_whichsig_sv(aTHX_ a)
 #define wrap_op_checker(a,b,c) Perl_wrap_op_checker(aTHX_ a,b,c)
+#if !(defined(HAS_MEMMEM))
+#define ninstr                 Perl_ninstr
+#endif
 #if !(defined(HAS_SIGACTION) && defined(SA_SIGINFO))
 #define csighandler            Perl_csighandler
 #endif
diff --git a/proto.h b/proto.h
index 3751f48..d16dd07 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -2319,11 +2319,6 @@ PERL_CALLCONV STRLEN *   Perl_new_warnings_bitfield(pTHX_ STRLEN *buffer, const ch
 PERL_CALLCONV PerlIO*  Perl_nextargv(pTHX_ GV* gv, bool nomagicopen);
 #define PERL_ARGS_ASSERT_NEXTARGV      \
        assert(gv)
-PERL_CALLCONV char*    Perl_ninstr(const char* big, const char* bigend, const char* little, const char* lend)
-                       __attribute__pure__;
-#define PERL_ARGS_ASSERT_NINSTR        \
-       assert(big); assert(bigend); assert(little); assert(lend)
-
 PERL_CALLCONV_NO_RET void      Perl_noperl_die(const char* pat, ...)
                        __attribute__noreturn__
                        __attribute__format__(__printf__,1,2);
@@ -3690,6 +3685,13 @@ STATIC int       S_sv_2iuv_non_preserve(pTHX_ SV *const sv);
 #    endif
 #  endif
 #endif
+#if !(defined(HAS_MEMMEM))
+PERL_CALLCONV char*    Perl_ninstr(const char* big, const char* bigend, const char* little, const char* lend)
+                       __attribute__pure__;
+#define PERL_ARGS_ASSERT_NINSTR        \
+       assert(big); assert(bigend); assert(little); assert(lend)
+
+#endif
 #if !(defined(HAS_SIGACTION) && defined(SA_SIGINFO))
 PERL_CALLCONV Signal_t Perl_csighandler(int sig);
 PERL_CALLCONV Signal_t Perl_sighandler(int sig);
@@ -4037,6 +4039,13 @@ PERL_CALLCONV void       Perl_dump_sv_child(pTHX_ SV *sv);
 #define PERL_ARGS_ASSERT_DUMP_SV_CHILD \
        assert(sv)
 #endif
+#if defined(HAS_MEMMEM)
+PERL_CALLCONV char*    Perl_ninstr(const char* big, const char* bigend, const char* little, const char* lend)
+                       __attribute__pure__;
+#define PERL_ARGS_ASSERT_NINSTR        \
+       assert(big); assert(bigend); assert(little); assert(lend)
+
+#endif
 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
 PERL_CALLCONV I32      Perl_do_ipcctl(pTHX_ I32 optype, SV** mark, SV** sp);
 #define PERL_ARGS_ASSERT_DO_IPCCTL     \
diff --git a/util.c b/util.c
index 447a19f..2f78825 100644 (file)
--- a/util.c
+++ b/util.c
@@ -584,6 +584,11 @@ char *
 Perl_ninstr(const char *big, const char *bigend, const char *little, const char *lend)
 {
     PERL_ARGS_ASSERT_NINSTR;
+
+#ifdef HAS_MEMMEM
+    return ninstr(big, bigend, little, lend);
+#else
+
     if (little >= lend)
         return (char*)big;
     {
@@ -602,6 +607,9 @@ Perl_ninstr(const char *big, const char *bigend, const char *little, const char
         }
     }
     return NULL;
+
+#endif
+
 }
 
 /*
diff --git a/util.h b/util.h
index 3a74bd0..8f4171b 100644 (file)
--- a/util.h
+++ b/util.h
@@ -231,6 +231,11 @@ means arg not present, 1 is empty string/null byte */
 
 #define instr(haystack, needle) strstr(haystack, needle)
 
+#ifdef HAS_MEMMEM
+#   define ninstr(big, bigend, little, lend)                                \
+            ((char *) memmem(big, bigend - big, little, lend - little))
+#endif
+
 /*
  * ex: set ts=8 sts=4 sw=4 et:
  */