This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
find_first_differing_byte_pos
authorKarl Williamson <khw@cpan.org>
Tue, 19 Nov 2019 04:54:57 +0000 (21:54 -0700)
committerKarl Williamson <khw@cpan.org>
Wed, 20 Nov 2019 21:09:20 +0000 (14:09 -0700)
embed.fnc
embed.h
proto.h
regcomp.c

index 900c124..2ed99ab 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -2569,6 +2569,7 @@ ES        |void    |set_ANYOF_arg |NN RExC_state_t* const pRExC_state \
 ES     |void   |output_posix_warnings                                      \
                                |NN RExC_state_t *pRExC_state               \
                                |NN AV* posix_warnings
+EiT    |Size_t  |find_first_differing_byte_pos|NN const U8 * s1|NN const U8 * s2| const Size_t max
 ES     |AV*     |add_multi_match|NULLOK AV* multi_char_matches             \
                                |NN SV* multi_string                        \
                                |const STRLEN cp_count
diff --git a/embed.h b/embed.h
index 5b10384..4e22323 100644 (file)
--- a/embed.h
+++ b/embed.h
 #define compute_EXACTish       S_compute_EXACTish
 #define construct_ahocorasick_from_trie(a,b,c) S_construct_ahocorasick_from_trie(aTHX_ a,b,c)
 #define edit_distance          S_edit_distance
+#define find_first_differing_byte_pos  S_find_first_differing_byte_pos
 #define get_ANYOFM_contents(a) S_get_ANYOFM_contents(aTHX_ a)
 #define get_ANYOF_cp_list_for_ssc(a,b) S_get_ANYOF_cp_list_for_ssc(aTHX_ a,b)
 #define grok_bslash_N(a,b,c,d,e,f,g)   S_grok_bslash_N(aTHX_ a,b,c,d,e,f,g)
diff --git a/proto.h b/proto.h
index 009a966..4aa32de 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -5559,6 +5559,11 @@ STATIC int       S_edit_distance(const UV *src, const UV *tgt, const STRLEN x, const S
 #define PERL_ARGS_ASSERT_EDIT_DISTANCE \
        assert(src); assert(tgt)
 
+#ifndef PERL_NO_INLINE_FUNCTIONS
+PERL_STATIC_INLINE Size_t      S_find_first_differing_byte_pos(const U8 * s1, const U8 * s2, const Size_t max);
+#define PERL_ARGS_ASSERT_FIND_FIRST_DIFFERING_BYTE_POS \
+       assert(s1); assert(s2)
+#endif
 STATIC SV *    S_get_ANYOFM_contents(pTHX_ const regnode * n)
                        __attribute__warn_unused_result__;
 #define PERL_ARGS_ASSERT_GET_ANYOFM_CONTENTS   \
index 5845b4d..b9ca619 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -16774,6 +16774,22 @@ S_output_posix_warnings(pTHX_ RExC_state_t *pRExC_state, AV* posix_warnings)
     UPDATE_WARNINGS_LOC(RExC_parse);
 }
 
+Size_t PERL_STATIC_INLINE
+S_find_first_differing_byte_pos(const U8 * s1, const U8 * s2, const Size_t max)
+{
+    const U8 * const start = s1;
+    const U8 * const send = start + max;
+
+    PERL_ARGS_ASSERT_FIND_FIRST_DIFFERING_BYTE_POS;
+
+    while (s1 < send && *s1  == *s2) {
+        s1++; s2++;
+    }
+
+    return s1 - start;
+}
+
+
 STATIC AV *
 S_add_multi_match(pTHX_ AV* multi_char_matches, SV* multi_string, const STRLEN cp_count)
 {