In perl.git, the branch blead has been updated

<https://perl5.git.perl.org/perl.git/commitdiff/dd237e826e98a1f24e4b18cc6176152da1f1fd58?hp=bb1b88dd7be03975ef001e007081e75d83f8cb6f>

- Log -----------------------------------------------------------------
commit dd237e826e98a1f24e4b18cc6176152da1f1fd58
Author: Karl Williamson <k...@cpan.org>
Date:   Sat Nov 18 13:52:44 2017 -0700

    Change 3 functions to be #defines of others
    
    I made these separate functions because I thought it would make faster
    code, but I realized that modern compilers should be able to optimize
    the more general functions into the same code as the ones removed by
    this commit, given that the parameters are known to be 0 at compile
    time.
    
    It's easier to maintain one version of a function than two, so this
    commit favors that.

commit f60f61fd47355f97bcac52e6e93e5cba818d1796
Author: Karl Williamson <k...@cpan.org>
Date:   Fri Nov 17 21:59:59 2017 -0700

    inline.h: Avoid some extra strlen()
    
    The API of these functions says that if the length is 0, strlen() is
    called to compute it.  In several cases, control is handed off to a
    function using 0, throwing away the already-computed length.  Change
    to use the computed length when calling the functions, avoiding the
    issue.

-----------------------------------------------------------------------

Summary of changes:
 embed.fnc | 14 +++++------
 embed.h   |  3 ---
 inline.h  | 82 +++++++++++++--------------------------------------------------
 proto.h   | 32 ++++++++-----------------
 4 files changed, 34 insertions(+), 97 deletions(-)

diff --git a/embed.fnc b/embed.fnc
index 39060f0bcf..6f566da1c2 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -786,25 +786,25 @@ AmnpdRP   |bool   |is_ascii_string|NN const U8* const 
s|const STRLEN len
 AmnpdRP        |bool   |is_invariant_string|NN const U8* const s|const STRLEN 
len
 AnpdD  |STRLEN |is_utf8_char   |NN const U8 *s
 Abmnpd |STRLEN |is_utf8_char_buf|NN const U8 *buf|NN const U8 *buf_end
-AnipdR |bool   |is_utf8_string |NN const U8 *s|const STRLEN len
+AnmdpR |bool   |is_utf8_string |NN const U8 *s|STRLEN len
 AnidR  |bool   |is_utf8_string_flags                                       \
-               |NN const U8 *s|const STRLEN len|const U32 flags
-AnidR  |bool   |is_strict_utf8_string|NN const U8 *s|const STRLEN len
-AnidR  |bool   |is_c9strict_utf8_string|NN const U8 *s|const STRLEN len
+               |NN const U8 *s|STRLEN len|const U32 flags
+AnmdpR |bool   |is_strict_utf8_string|NN const U8 *s|STRLEN len
+AnmdpR |bool   |is_c9strict_utf8_string|NN const U8 *s|STRLEN len
 Anpdmb |bool   |is_utf8_string_loc                                         \
                |NN const U8 *s|const STRLEN len|NN const U8 **ep
 Andm   |bool   |is_utf8_string_loc_flags                                   \
-               |NN const U8 *s|const STRLEN len|NN const U8 **ep           \
+               |NN const U8 *s|STRLEN len|NN const U8 **ep                 \
                |const U32 flags
 Andm   |bool   |is_strict_utf8_string_loc                                  \
                |NN const U8 *s|const STRLEN len|NN const U8 **ep
 Andm   |bool   |is_c9strict_utf8_string_loc                                \
                |NN const U8 *s|const STRLEN len|NN const U8 **ep
 Anipd  |bool   |is_utf8_string_loclen                                      \
-               |NN const U8 *s|const STRLEN len|NULLOK const U8 **ep       \
+               |NN const U8 *s|STRLEN len|NULLOK const U8 **ep             \
                |NULLOK STRLEN *el
 Anid   |bool   |is_utf8_string_loclen_flags                                \
-               |NN const U8 *s|const STRLEN len|NULLOK const U8 **ep       \
+               |NN const U8 *s|STRLEN len|NULLOK const U8 **ep             \
                |NULLOK STRLEN *el|const U32 flags
 Anid   |bool   |is_strict_utf8_string_loclen                               \
                |NN const U8 *s|const STRLEN len|NULLOK const U8 **ep       \
diff --git a/embed.h b/embed.h
index 13277fc40c..5d67b9756f 100644
--- a/embed.h
+++ b/embed.h
@@ -246,11 +246,9 @@
 #define intro_my()             Perl_intro_my(aTHX)
 #define isALNUM_lazy(a)                Perl_isALNUM_lazy(aTHX_ a)
 #define isIDFIRST_lazy(a)      Perl_isIDFIRST_lazy(aTHX_ a)
-#define is_c9strict_utf8_string        S_is_c9strict_utf8_string
 #define is_c9strict_utf8_string_loclen S_is_c9strict_utf8_string_loclen
 #define is_lvalue_sub()                Perl_is_lvalue_sub(aTHX)
 #define is_safe_syscall(a,b,c,d)       S_is_safe_syscall(aTHX_ a,b,c,d)
-#define is_strict_utf8_string  S_is_strict_utf8_string
 #define is_strict_utf8_string_loclen   S_is_strict_utf8_string_loclen
 #define is_uni_alnum(a)                Perl_is_uni_alnum(aTHX_ a)
 #define is_uni_alnum_lc(a)     Perl_is_uni_alnum_lc(aTHX_ a)
@@ -303,7 +301,6 @@
 #define is_utf8_print(a)       Perl_is_utf8_print(aTHX_ a)
 #define is_utf8_punct(a)       Perl_is_utf8_punct(aTHX_ a)
 #define is_utf8_space(a)       Perl_is_utf8_space(aTHX_ a)
-#define is_utf8_string         Perl_is_utf8_string
 #define is_utf8_string_flags   S_is_utf8_string_flags
 #define is_utf8_string_loclen  Perl_is_utf8_string_loclen
 #define is_utf8_string_loclen_flags    S_is_utf8_string_loclen_flags
diff --git a/inline.h b/inline.h
index ddafde9650..aa8798ed59 100644
--- a/inline.h
+++ b/inline.h
@@ -484,27 +484,7 @@ C<L</is_utf8_fixed_width_buf_loclen_flags>>,
 =cut
 */
 
-PERL_STATIC_INLINE bool
-Perl_is_utf8_string(const U8 *s, const STRLEN len)
-{
-    /* This is now marked pure in embed.fnc, because isUTF8_CHAR now is pure.
-     * Be aware of possible changes to that */
-
-    const U8* const send = s + (len ? len : strlen((const char *)s));
-    const U8* x = s;
-
-    PERL_ARGS_ASSERT_IS_UTF8_STRING;
-
-    while (x < send) {
-        const STRLEN cur_len = isUTF8_CHAR(x, send);
-        if (UNLIKELY(! cur_len)) {
-            return FALSE;
-        }
-        x += cur_len;
-    }
-
-    return TRUE;
-}
+#define is_utf8_string(s, len)  is_utf8_string_loclen(s, len, NULL, NULL)
 
 /*
 =for apidoc is_strict_utf8_string
@@ -542,24 +522,7 @@ C<L</is_c9strict_utf8_string_loclen>>.
 =cut
 */
 
-PERL_STATIC_INLINE bool
-S_is_strict_utf8_string(const U8 *s, const STRLEN len)
-{
-    const U8* const send = s + (len ? len : strlen((const char *)s));
-    const U8* x = s;
-
-    PERL_ARGS_ASSERT_IS_STRICT_UTF8_STRING;
-
-    while (x < send) {
-        const STRLEN cur_len = isSTRICT_UTF8_CHAR(x, send);
-        if (UNLIKELY(! cur_len)) {
-            return FALSE;
-        }
-        x += cur_len;
-    }
-
-    return TRUE;
-}
+#define is_strict_utf8_string(s, len)  is_strict_utf8_string_loclen(s, len, 
NULL, NULL)
 
 /*
 =for apidoc is_c9strict_utf8_string
@@ -599,28 +562,7 @@ C<L</is_c9strict_utf8_string_loclen>>.
 =cut
 */
 
-PERL_STATIC_INLINE bool
-S_is_c9strict_utf8_string(const U8 *s, const STRLEN len)
-{
-    const U8* const send = s + (len ? len : strlen((const char *)s));
-    const U8* x = s;
-
-    PERL_ARGS_ASSERT_IS_C9STRICT_UTF8_STRING;
-
-    while (x < send) {
-        const STRLEN cur_len = isC9_STRICT_UTF8_CHAR(x, send);
-        if (UNLIKELY(! cur_len)) {
-            return FALSE;
-        }
-        x += cur_len;
-    }
-
-    return TRUE;
-}
-
-/* The above 3 functions could have been moved into the more general one just
- * below, and made #defines that call it with the right 'flags'.  They are
- * currently kept separate to increase their chances of getting inlined */
+#define is_c9strict_utf8_string(s, len)  is_c9strict_utf8_string_loclen(s, 
len, NULL, 0)
 
 /*
 =for apidoc is_utf8_string_flags
@@ -663,15 +605,19 @@ C<L</is_c9strict_utf8_string_loclen>>.
 */
 
 PERL_STATIC_INLINE bool
-S_is_utf8_string_flags(const U8 *s, const STRLEN len, const U32 flags)
+S_is_utf8_string_flags(const U8 *s, STRLEN len, const U32 flags)
 {
-    const U8* const send = s + (len ? len : strlen((const char *)s));
+    const U8* send;
     const U8* x = s;
 
     PERL_ARGS_ASSERT_IS_UTF8_STRING_FLAGS;
     assert(0 == (flags & ~(UTF8_DISALLOW_ILLEGAL_INTERCHANGE
                           |UTF8_DISALLOW_PERL_EXTENDED)));
 
+    if (len == 0) {
+        len = strlen((const char *)s);
+    }
+
     if (flags == 0) {
         return is_utf8_string(s, len);
     }
@@ -688,6 +634,7 @@ S_is_utf8_string_flags(const U8 *s, const STRLEN len, const 
U32 flags)
         return is_c9strict_utf8_string(s, len);
     }
 
+    send = s + len;
     while (x < send) {
         STRLEN cur_len = isUTF8_CHAR_flags(x, send, flags);
         if (UNLIKELY(! cur_len)) {
@@ -908,9 +855,9 @@ See also C<L</is_utf8_string_loc_flags>>.
 */
 
 PERL_STATIC_INLINE bool
-S_is_utf8_string_loclen_flags(const U8 *s, const STRLEN len, const U8 **ep, 
STRLEN *el, const U32 flags)
+S_is_utf8_string_loclen_flags(const U8 *s, STRLEN len, const U8 **ep, STRLEN 
*el, const U32 flags)
 {
-    const U8* const send = s + (len ? len : strlen((const char *)s));
+    const U8* send;
     const U8* x = s;
     STRLEN outlen = 0;
 
@@ -918,6 +865,10 @@ S_is_utf8_string_loclen_flags(const U8 *s, const STRLEN 
len, const U8 **ep, STRL
     assert(0 == (flags & ~(UTF8_DISALLOW_ILLEGAL_INTERCHANGE
                           |UTF8_DISALLOW_PERL_EXTENDED)));
 
+    if (len == 0) {
+        len = strlen((const char *)s);
+    }
+
     if (flags == 0) {
         return is_utf8_string_loclen(s, len, ep, el);
     }
@@ -934,6 +885,7 @@ S_is_utf8_string_loclen_flags(const U8 *s, const STRLEN 
len, const U8 **ep, STRL
         return is_c9strict_utf8_string_loclen(s, len, ep, el);
     }
 
+    send = s + len;
     while (x < send) {
         const STRLEN cur_len = isUTF8_CHAR_flags(x, send, flags);
         if (UNLIKELY(! cur_len)) {
diff --git a/proto.h b/proto.h
index 598e7c1c04..c7fcd86eb7 100644
--- a/proto.h
+++ b/proto.h
@@ -1379,12 +1379,8 @@ PERL_CALLCONV bool       Perl_isIDFIRST_lazy(pTHX_ const 
char* p)
                        __attribute__warn_unused_result__
                        __attribute__pure__; */
 
-#ifndef PERL_NO_INLINE_FUNCTIONS
-PERL_STATIC_INLINE bool        S_is_c9strict_utf8_string(const U8 *s, const 
STRLEN len)
-                       __attribute__warn_unused_result__;
-#define PERL_ARGS_ASSERT_IS_C9STRICT_UTF8_STRING       \
-       assert(s)
-#endif
+/* PERL_CALLCONV bool  Perl_is_c9strict_utf8_string(const U8 *s, STRLEN len)
+                       __attribute__warn_unused_result__; */
 
 /* PERL_CALLCONV bool  is_c9strict_utf8_string_loc(const U8 *s, const STRLEN 
len, const U8 **ep); */
 #ifndef PERL_NO_INLINE_FUNCTIONS
@@ -1406,12 +1402,8 @@ PERL_STATIC_INLINE bool  S_is_safe_syscall(pTHX_ const 
char *pv, STRLEN len, cons
        assert(pv); assert(what); assert(op_name)
 #endif
 
-#ifndef PERL_NO_INLINE_FUNCTIONS
-PERL_STATIC_INLINE bool        S_is_strict_utf8_string(const U8 *s, const 
STRLEN len)
-                       __attribute__warn_unused_result__;
-#define PERL_ARGS_ASSERT_IS_STRICT_UTF8_STRING \
-       assert(s)
-#endif
+/* PERL_CALLCONV bool  Perl_is_strict_utf8_string(const U8 *s, STRLEN len)
+                       __attribute__warn_unused_result__; */
 
 /* PERL_CALLCONV bool  is_strict_utf8_string_loc(const U8 *s, const STRLEN 
len, const U8 **ep); */
 #ifndef PERL_NO_INLINE_FUNCTIONS
@@ -1684,15 +1676,11 @@ PERL_CALLCONV bool      Perl_is_utf8_space(pTHX_ const 
U8 *p)
 #define PERL_ARGS_ASSERT_IS_UTF8_SPACE \
        assert(p)
 
-#ifndef PERL_NO_INLINE_FUNCTIONS
-PERL_STATIC_INLINE bool        Perl_is_utf8_string(const U8 *s, const STRLEN 
len)
-                       __attribute__warn_unused_result__;
-#define PERL_ARGS_ASSERT_IS_UTF8_STRING        \
-       assert(s)
-#endif
+/* PERL_CALLCONV bool  Perl_is_utf8_string(const U8 *s, STRLEN len)
+                       __attribute__warn_unused_result__; */
 
 #ifndef PERL_NO_INLINE_FUNCTIONS
-PERL_STATIC_INLINE bool        S_is_utf8_string_flags(const U8 *s, const 
STRLEN len, const U32 flags)
+PERL_STATIC_INLINE bool        S_is_utf8_string_flags(const U8 *s, STRLEN len, 
const U32 flags)
                        __attribute__warn_unused_result__;
 #define PERL_ARGS_ASSERT_IS_UTF8_STRING_FLAGS  \
        assert(s)
@@ -1703,14 +1691,14 @@ PERL_CALLCONV bool      Perl_is_utf8_string_loc(const 
U8 *s, const STRLEN len, const
 #define PERL_ARGS_ASSERT_IS_UTF8_STRING_LOC    \
        assert(s); assert(ep)
 #endif
-/* PERL_CALLCONV bool  is_utf8_string_loc_flags(const U8 *s, const STRLEN len, 
const U8 **ep, const U32 flags); */
+/* PERL_CALLCONV bool  is_utf8_string_loc_flags(const U8 *s, STRLEN len, const 
U8 **ep, const U32 flags); */
 #ifndef PERL_NO_INLINE_FUNCTIONS
-PERL_STATIC_INLINE bool        Perl_is_utf8_string_loclen(const U8 *s, const 
STRLEN len, const U8 **ep, STRLEN *el);
+PERL_STATIC_INLINE bool        Perl_is_utf8_string_loclen(const U8 *s, STRLEN 
len, const U8 **ep, STRLEN *el);
 #define PERL_ARGS_ASSERT_IS_UTF8_STRING_LOCLEN \
        assert(s)
 #endif
 #ifndef PERL_NO_INLINE_FUNCTIONS
-PERL_STATIC_INLINE bool        S_is_utf8_string_loclen_flags(const U8 *s, 
const STRLEN len, const U8 **ep, STRLEN *el, const U32 flags);
+PERL_STATIC_INLINE bool        S_is_utf8_string_loclen_flags(const U8 *s, 
STRLEN len, const U8 **ep, STRLEN *el, const U32 flags);
 #define PERL_ARGS_ASSERT_IS_UTF8_STRING_LOCLEN_FLAGS   \
        assert(s)
 #endif

-- 
Perl5 Master Repository

Reply via email to