diff options
author | Karl Williamson <khw@cpan.org> | 2017-02-19 21:48:40 -0700 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2017-02-19 22:45:00 -0700 |
commit | ec2c235b8da47c613eb6c9cdac160311692ea63a (patch) | |
tree | 699f93ca8e3f57be27bf6348238cbf0cb385232d | |
parent | 4d2c9c8c6c9a82ad785b57b9e346e202f74a0c66 (diff) | |
download | perl-ec2c235b8da47c613eb6c9cdac160311692ea63a.tar.gz |
Inline foldEQ, foldEQ_latin1, foldEQ_locale
These short functions are called in inner loops and regex backtracking.
-rw-r--r-- | embed.fnc | 6 | ||||
-rw-r--r-- | inline.h | 86 | ||||
-rw-r--r-- | proto.h | 15 | ||||
-rw-r--r-- | util.c | 83 |
4 files changed, 92 insertions, 98 deletions
@@ -679,9 +679,9 @@ ApbmM |SV** |hv_store_flags |NULLOK HV *hv|NULLOK const char *key \ Amd |void |hv_undef |NULLOK HV *hv poX |void |hv_undef_flags |NULLOK HV *hv|U32 flags AmP |I32 |ibcmp |NN const char* a|NN const char* b|I32 len -AnpP |I32 |foldEQ |NN const char* a|NN const char* b|I32 len +Ainp |I32 |foldEQ |NN const char* a|NN const char* b|I32 len AmP |I32 |ibcmp_locale |NN const char* a|NN const char* b|I32 len -AnpP |I32 |foldEQ_locale |NN const char* a|NN const char* b|I32 len +Ainp |I32 |foldEQ_locale |NN const char* a|NN const char* b|I32 len Am |I32 |ibcmp_utf8 |NN const char *s1|NULLOK char **pe1|UV l1 \ |bool u1|NN const char *s2|NULLOK char **pe2 \ |UV l2|bool u2 @@ -691,7 +691,7 @@ Amd |I32 |foldEQ_utf8 |NN const char *s1|NULLOK char **pe1|UV l1 \ AMp |I32 |foldEQ_utf8_flags |NN const char *s1|NULLOK char **pe1|UV l1 \ |bool u1|NN const char *s2|NULLOK char **pe2 \ |UV l2|bool u2|U32 flags -AnpP |I32 |foldEQ_latin1 |NN const char* a|NN const char* b|I32 len +Ainp |I32 |foldEQ_latin1 |NN const char* a|NN const char* b|I32 len #if defined(PERL_IN_DOIO_C) sR |bool |ingroup |Gid_t testgid|bool effective #endif @@ -1645,6 +1645,92 @@ S_cx_popgiven(pTHX_ PERL_CONTEXT *cx) SvREFCNT_dec(sv); } +/* ------------------ util.h ------------------------------------------- */ + +/* +=head1 Miscellaneous Functions + +=for apidoc foldEQ + +Returns true if the leading C<len> bytes of the strings C<s1> and C<s2> are the +same +case-insensitively; false otherwise. Uppercase and lowercase ASCII range bytes +match themselves and their opposite case counterparts. Non-cased and non-ASCII +range bytes match only themselves. + +=cut +*/ + +PERL_STATIC_INLINE I32 +Perl_foldEQ(const char *s1, const char *s2, I32 len) +{ + const U8 *a = (const U8 *)s1; + const U8 *b = (const U8 *)s2; + + PERL_ARGS_ASSERT_FOLDEQ; + + assert(len >= 0); + + while (len--) { + if (*a != *b && *a != PL_fold[*b]) + return 0; + a++,b++; + } + return 1; +} + +I32 +Perl_foldEQ_latin1(const char *s1, const char *s2, I32 len) +{ + /* Compare non-utf8 using Unicode (Latin1) semantics. Does not work on + * MICRO_SIGN, LATIN_SMALL_LETTER_SHARP_S, nor + * LATIN_SMALL_LETTER_Y_WITH_DIAERESIS, and does not check for these. Nor + * does it check that the strings each have at least 'len' characters */ + + const U8 *a = (const U8 *)s1; + const U8 *b = (const U8 *)s2; + + PERL_ARGS_ASSERT_FOLDEQ_LATIN1; + + assert(len >= 0); + + while (len--) { + if (*a != *b && *a != PL_fold_latin1[*b]) { + return 0; + } + a++, b++; + } + return 1; +} + +/* +=for apidoc foldEQ_locale + +Returns true if the leading C<len> bytes of the strings C<s1> and C<s2> are the +same case-insensitively in the current locale; false otherwise. + +=cut +*/ + +I32 +Perl_foldEQ_locale(const char *s1, const char *s2, I32 len) +{ + dVAR; + const U8 *a = (const U8 *)s1; + const U8 *b = (const U8 *)s2; + + PERL_ARGS_ASSERT_FOLDEQ_LOCALE; + + assert(len >= 0); + + while (len--) { + if (*a != *b && *a != PL_fold_locale[*b]) + return 0; + a++,b++; + } + return 1; +} + /* * ex: set ts=8 sts=4 sw=4 et: */ @@ -886,24 +886,15 @@ PERL_CALLCONV PADOFFSET Perl_find_rundefsvoffset(pTHX) PERL_CALLCONV char* Perl_find_script(pTHX_ const char *scriptname, bool dosearch, const char *const *const search_ext, I32 flags); #define PERL_ARGS_ASSERT_FIND_SCRIPT \ assert(scriptname) -PERL_CALLCONV I32 Perl_foldEQ(const char* a, const char* b, I32 len) - __attribute__warn_unused_result__ - __attribute__pure__; +PERL_STATIC_INLINE I32 Perl_foldEQ(const char* a, const char* b, I32 len); #define PERL_ARGS_ASSERT_FOLDEQ \ assert(a); assert(b) - -PERL_CALLCONV I32 Perl_foldEQ_latin1(const char* a, const char* b, I32 len) - __attribute__warn_unused_result__ - __attribute__pure__; +PERL_STATIC_INLINE I32 Perl_foldEQ_latin1(const char* a, const char* b, I32 len); #define PERL_ARGS_ASSERT_FOLDEQ_LATIN1 \ assert(a); assert(b) - -PERL_CALLCONV I32 Perl_foldEQ_locale(const char* a, const char* b, I32 len) - __attribute__warn_unused_result__ - __attribute__pure__; +PERL_STATIC_INLINE I32 Perl_foldEQ_locale(const char* a, const char* b, I32 len); #define PERL_ARGS_ASSERT_FOLDEQ_LOCALE \ assert(a); assert(b) - /* PERL_CALLCONV I32 foldEQ_utf8(pTHX_ const char *s1, char **pe1, UV l1, bool u1, const char *s2, char **pe2, UV l2, bool u2); */ PERL_CALLCONV I32 Perl_foldEQ_utf8_flags(pTHX_ const char *s1, char **pe1, UV l1, bool u1, const char *s2, char **pe2, UV l2, bool u2, U32 flags); #define PERL_ARGS_ASSERT_FOLDEQ_UTF8_FLAGS \ @@ -1022,89 +1022,6 @@ Perl_fbm_instr(pTHX_ unsigned char *big, unsigned char *bigend, SV *littlestr, U } } - -/* -=for apidoc foldEQ - -Returns true if the leading C<len> bytes of the strings C<s1> and C<s2> are the -same -case-insensitively; false otherwise. Uppercase and lowercase ASCII range bytes -match themselves and their opposite case counterparts. Non-cased and non-ASCII -range bytes match only themselves. - -=cut -*/ - - -I32 -Perl_foldEQ(const char *s1, const char *s2, I32 len) -{ - const U8 *a = (const U8 *)s1; - const U8 *b = (const U8 *)s2; - - PERL_ARGS_ASSERT_FOLDEQ; - - assert(len >= 0); - - while (len--) { - if (*a != *b && *a != PL_fold[*b]) - return 0; - a++,b++; - } - return 1; -} -I32 -Perl_foldEQ_latin1(const char *s1, const char *s2, I32 len) -{ - /* Compare non-utf8 using Unicode (Latin1) semantics. Does not work on - * MICRO_SIGN, LATIN_SMALL_LETTER_SHARP_S, nor - * LATIN_SMALL_LETTER_Y_WITH_DIAERESIS, and does not check for these. Nor - * does it check that the strings each have at least 'len' characters */ - - const U8 *a = (const U8 *)s1; - const U8 *b = (const U8 *)s2; - - PERL_ARGS_ASSERT_FOLDEQ_LATIN1; - - assert(len >= 0); - - while (len--) { - if (*a != *b && *a != PL_fold_latin1[*b]) { - return 0; - } - a++, b++; - } - return 1; -} - -/* -=for apidoc foldEQ_locale - -Returns true if the leading C<len> bytes of the strings C<s1> and C<s2> are the -same case-insensitively in the current locale; false otherwise. - -=cut -*/ - -I32 -Perl_foldEQ_locale(const char *s1, const char *s2, I32 len) -{ - dVAR; - const U8 *a = (const U8 *)s1; - const U8 *b = (const U8 *)s2; - - PERL_ARGS_ASSERT_FOLDEQ_LOCALE; - - assert(len >= 0); - - while (len--) { - if (*a != *b && *a != PL_fold_locale[*b]) - return 0; - a++,b++; - } - return 1; -} - /* copy a string to a safe spot */ /* |