This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
utf8.c: Move a static function to inline.h
authorKarl Williamson <khw@cpan.org>
Tue, 6 May 2014 01:37:58 +0000 (19:37 -0600)
committerKarl Williamson <khw@cpan.org>
Sat, 31 May 2014 17:37:24 +0000 (11:37 -0600)
This is in preparation for it being called from outside utf8.c.  It is
renamed to have a leading underscore to emphasize its private nature

embed.fnc
embed.h
inline.h
proto.h
utf8.c

index cb2d7b1..9d6915d 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -633,6 +633,7 @@ pR  |OP*    |invert         |NULLOK OP* cmd
 ApR    |I32    |is_lvalue_sub
 : Used in cop.h
 XopR   |I32    |was_lvalue_sub
+iRn    |STRLEN |_is_utf8_char_slow|NN const U8 *s|const STRLEN len
 ADMpPR |U32    |to_uni_upper_lc|U32 c
 ADMpPR |U32    |to_uni_title_lc|U32 c
 ADMpPR |U32    |to_uni_lower_lc|U32 c
@@ -2393,7 +2394,6 @@ sn        |NV|mulexp10    |NV value|I32 exponent
 #endif
 
 #if defined(PERL_IN_UTF8_C)
-iRn    |STRLEN |is_utf8_char_slow|NN const U8 *s|const STRLEN len
 sRM    |UV     |check_locale_boundary_crossing|NN const U8* const p|const UV result|NN U8* const ustrp|NN STRLEN *lenp
 iR     |bool   |is_utf8_common |NN const U8 *const p|NN SV **swash|NN const char * const swashname|NULLOK SV* const invlist
 sR     |SV*    |swatch_get     |NN SV* swash|UV start|UV span
diff --git a/embed.h b/embed.h
index 0e33aff..5ad8ef6 100644 (file)
--- a/embed.h
+++ b/embed.h
 #ifdef PERL_CORE
 #define Slab_Alloc(a)          Perl_Slab_Alloc(aTHX_ a)
 #define Slab_Free(a)           Perl_Slab_Free(aTHX_ a)
+#define _is_utf8_char_slow     S__is_utf8_char_slow
 #define allocmy(a,b,c)         Perl_allocmy(aTHX_ a,b,c)
 #define amagic_is_enabled(a)   Perl_amagic_is_enabled(aTHX_ a)
 #define apply(a,b,c)           Perl_apply(aTHX_ a,b,c)
 #  endif
 #  if defined(PERL_IN_UTF8_C)
 #define check_locale_boundary_crossing(a,b,c,d)        S_check_locale_boundary_crossing(aTHX_ a,b,c,d)
-#define is_utf8_char_slow      S_is_utf8_char_slow
 #define is_utf8_common(a,b,c,d)        S_is_utf8_common(aTHX_ a,b,c,d)
 #define swash_scan_list_line(a,b,c,d,e,f,g)    S_swash_scan_list_line(aTHX_ a,b,c,d,e,f,g)
 #define swatch_get(a,b,c)      S_swatch_get(aTHX_ a,b,c)
index 615c2e3..34d9b3b 100644 (file)
--- a/inline.h
+++ b/inline.h
@@ -238,6 +238,37 @@ S_isALNUM_lazy(pTHX_ const char* p)
     return isALNUM_lazy_if(p,1);
 }
 
+/*
+Tests if the first C<len> bytes of string C<s> form a valid UTF-8
+character.  Note that an INVARIANT (i.e. ASCII on non-EBCDIC) character is a
+valid UTF-8 character.  The number of bytes in the UTF-8 character
+will be returned if it is valid, otherwise 0.
+
+This is the "slow" version as opposed to the "fast" version which is
+the "unrolled" IS_UTF8_CHAR().  E.g. for t/uni/class.t the speed
+difference is a factor of 2 to 3.  For lengths (UTF8SKIP(s)) of four
+or less you should use the IS_UTF8_CHAR(), for lengths of five or more
+you should use the _slow().  In practice this means that the _slow()
+will be used very rarely, since the maximum Unicode code point (as of
+Unicode 4.1) is U+10FFFF, which encodes in UTF-8 to four bytes.  Only
+the "Perl extended UTF-8" (e.g, the infamous 'v-strings') will encode into
+five bytes or more.
+
+=cut */
+PERL_STATIC_INLINE STRLEN
+S__is_utf8_char_slow(const U8 *s, const STRLEN len)
+{
+    dTHX;   /* The function called below requires thread context */
+
+    STRLEN actual_len;
+
+    PERL_ARGS_ASSERT__IS_UTF8_CHAR_SLOW;
+
+    utf8n_to_uvchr(s, len, &actual_len, UTF8_CHECK_ONLY);
+
+    return (actual_len == (STRLEN) -1) ? 0 : actual_len;
+}
+
 /* ------------------------------- perl.h ----------------------------- */
 
 /*
diff --git a/proto.h b/proto.h
index 06a31e3..2d50a75 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -57,6 +57,12 @@ PERL_CALLCONV bool   Perl__is_utf8_FOO(pTHX_ const U8 classnum, const U8 *p)
 #define PERL_ARGS_ASSERT__IS_UTF8_FOO  \
        assert(p)
 
+PERL_STATIC_INLINE STRLEN      S__is_utf8_char_slow(const U8 *s, const STRLEN len)
+                       __attribute__warn_unused_result__
+                       __attribute__nonnull__(1);
+#define PERL_ARGS_ASSERT__IS_UTF8_CHAR_SLOW    \
+       assert(s)
+
 PERL_CALLCONV bool     Perl__is_utf8_mark(pTHX_ const U8 *p)
                        __attribute__warn_unused_result__
                        __attribute__nonnull__(pTHX_1);
@@ -7692,12 +7698,6 @@ STATIC UV        S_check_locale_boundary_crossing(pTHX_ const U8* const p, const UV res
 #define PERL_ARGS_ASSERT_CHECK_LOCALE_BOUNDARY_CROSSING        \
        assert(p); assert(ustrp); assert(lenp)
 
-PERL_STATIC_INLINE STRLEN      S_is_utf8_char_slow(const U8 *s, const STRLEN len)
-                       __attribute__warn_unused_result__
-                       __attribute__nonnull__(1);
-#define PERL_ARGS_ASSERT_IS_UTF8_CHAR_SLOW     \
-       assert(s)
-
 PERL_STATIC_INLINE bool        S_is_utf8_common(pTHX_ const U8 *const p, SV **swash, const char * const swashname, SV* const invlist)
                        __attribute__warn_unused_result__
                        __attribute__nonnull__(pTHX_1)
diff --git a/utf8.c b/utf8.c
index aa13a59..d4cbbe7 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -308,38 +308,6 @@ Perl_uvchr_to_utf8_flags(pTHX_ U8 *d, UV uv, UV flags)
 }
 
 /*
-
-Tests if the first C<len> bytes of string C<s> form a valid UTF-8
-character.  Note that an INVARIANT (i.e. ASCII on non-EBCDIC) character is a
-valid UTF-8 character.  The number of bytes in the UTF-8 character
-will be returned if it is valid, otherwise 0.
-
-This is the "slow" version as opposed to the "fast" version which is
-the "unrolled" IS_UTF8_CHAR().  E.g. for t/uni/class.t the speed
-difference is a factor of 2 to 3.  For lengths (UTF8SKIP(s)) of four
-or less you should use the IS_UTF8_CHAR(), for lengths of five or more
-you should use the _slow().  In practice this means that the _slow()
-will be used very rarely, since the maximum Unicode code point (as of
-Unicode 4.1) is U+10FFFF, which encodes in UTF-8 to four bytes.  Only
-the "Perl extended UTF-8" (e.g, the infamous 'v-strings') will encode into
-five bytes or more.
-
-=cut */
-PERL_STATIC_INLINE STRLEN
-S_is_utf8_char_slow(const U8 *s, const STRLEN len)
-{
-    dTHX;   /* The function called below requires thread context */
-
-    STRLEN actual_len;
-
-    PERL_ARGS_ASSERT_IS_UTF8_CHAR_SLOW;
-
-    utf8n_to_uvchr(s, len, &actual_len, UTF8_CHECK_ONLY);
-
-    return (actual_len == (STRLEN) -1) ? 0 : actual_len;
-}
-
-/*
 =for apidoc is_utf8_char_buf
 
 Returns the number of bytes that comprise the first UTF-8 encoded character in
@@ -371,7 +339,7 @@ Perl_is_utf8_char_buf(const U8 *buf, const U8* buf_end)
 
     if (IS_UTF8_CHAR_FAST(len))
         return IS_UTF8_CHAR(buf, len) ? len : 0;
-    return is_utf8_char_slow(buf, len);
+    return _is_utf8_char_slow(buf, len);
 }
 
 /*
@@ -438,7 +406,7 @@ Perl_is_utf8_string(const U8 *s, STRLEN len)
                 if (!IS_UTF8_CHAR(x, c))
                     return FALSE;
             }
-            else if (! is_utf8_char_slow(x, c)) {
+            else if (! _is_utf8_char_slow(x, c)) {
                 return FALSE;
             }
             x = next_char_ptr;
@@ -498,7 +466,7 @@ Perl_is_utf8_string_loclen(const U8 *s, STRLEN len, const U8 **ep, STRLEN *el)
                 if (!IS_UTF8_CHAR(x, c))
                     c = 0;
             } else
-                c = is_utf8_char_slow(x, c);
+                c = _is_utf8_char_slow(x, c);
             if (!c)
                 goto out;
         }