Change 24730 by [EMAIL PROTECTED] on 2005/06/07 14:35:25

        Subject: [PATCH] one more round of is_utf8_foo tuneup
        From: Jarkko Hietaniemi <[EMAIL PROTECTED]>
        Date: Sun, 05 Jun 2005 18:06:12 +0300
        Message-ID: <[EMAIL PROTECTED]>

Affected files ...

... //depot/perl/embed.fnc#189 edit
... //depot/perl/embed.h#481 edit
... //depot/perl/global.sym#275 edit
... //depot/perl/mg.c#335 edit
... //depot/perl/pod/perlapi.pod#221 edit
... //depot/perl/proto.h#540 edit
... //depot/perl/utf8.c#236 edit
... //depot/perl/utf8.h#69 edit

Differences ...

==== //depot/perl/embed.fnc#189 (text) ====
Index: perl/embed.fnc
--- perl/embed.fnc#188~24706~   Sat Jun  4 09:55:27 2005
+++ perl/embed.fnc      Tue Jun  7 07:35:25 2005
@@ -346,7 +346,8 @@
 ApPR   |bool   |is_uni_xdigit_lc|UV c
 Apd    |STRLEN |is_utf8_char   |NN const U8 *p
 Apd    |bool   |is_utf8_string |NN const U8 *s|STRLEN len
-Apd    |bool   |is_utf8_string_loc|NN const U8 *s|STRLEN len|NN const U8 **p
+Apd    |bool   |is_utf8_string_loc|NN const U8 *s|STRLEN len|const U8 **p
+Apd    |bool   |is_utf8_string_loclen|NN const U8 *s|STRLEN len|const U8 
**ep|STRLEN *el
 ApR    |bool   |is_utf8_alnum  |NN const U8 *p
 ApR    |bool   |is_utf8_alnumc |NN const U8 *p
 ApR    |bool   |is_utf8_idfirst|NN const U8 *p

==== //depot/perl/embed.h#481 (text+w) ====
Index: perl/embed.h
--- perl/embed.h#480~24706~     Sat Jun  4 09:55:27 2005
+++ perl/embed.h        Tue Jun  7 07:35:25 2005
@@ -345,6 +345,7 @@
 #define is_utf8_char           Perl_is_utf8_char
 #define is_utf8_string         Perl_is_utf8_string
 #define is_utf8_string_loc     Perl_is_utf8_string_loc
+#define is_utf8_string_loclen  Perl_is_utf8_string_loclen
 #define is_utf8_alnum          Perl_is_utf8_alnum
 #define is_utf8_alnumc         Perl_is_utf8_alnumc
 #define is_utf8_idfirst                Perl_is_utf8_idfirst
@@ -2344,6 +2345,7 @@
 #define is_utf8_char(a)                Perl_is_utf8_char(aTHX_ a)
 #define is_utf8_string(a,b)    Perl_is_utf8_string(aTHX_ a,b)
 #define is_utf8_string_loc(a,b,c)      Perl_is_utf8_string_loc(aTHX_ a,b,c)
+#define is_utf8_string_loclen(a,b,c,d) Perl_is_utf8_string_loclen(aTHX_ 
a,b,c,d)
 #define is_utf8_alnum(a)       Perl_is_utf8_alnum(aTHX_ a)
 #define is_utf8_alnumc(a)      Perl_is_utf8_alnumc(aTHX_ a)
 #define is_utf8_idfirst(a)     Perl_is_utf8_idfirst(aTHX_ a)

==== //depot/perl/global.sym#275 (text+w) ====
Index: perl/global.sym
--- perl/global.sym#274~24706~  Sat Jun  4 09:55:27 2005
+++ perl/global.sym     Tue Jun  7 07:35:25 2005
@@ -207,6 +207,7 @@
 Perl_is_utf8_char
 Perl_is_utf8_string
 Perl_is_utf8_string_loc
+Perl_is_utf8_string_loclen
 Perl_is_utf8_alnum
 Perl_is_utf8_alnumc
 Perl_is_utf8_idfirst

==== //depot/perl/mg.c#335 (text) ====
Index: perl/mg.c
--- perl/mg.c#334~24580~        Thu May 26 01:43:38 2005
+++ perl/mg.c   Tue Jun  7 07:35:25 2005
@@ -495,10 +495,12 @@
                if (i > 0 && RX_MATCH_UTF8(rx)) {
                    char *s    = rx->subbeg + s1;
                    char *send = rx->subbeg + t1;
+                   const U8 *ep;
+                   STRLEN el;
 
                     i = t1 - s1;
-                   if (is_utf8_string((U8*)s, i))
-                       i = Perl_utf8_length(aTHX_ (U8*)s, (U8*)send);
+                   if (is_utf8_string_loclen((U8*)s, i, &ep, &el))
+                       i = el;
                }
                if (i < 0)
                    Perl_croak(aTHX_ "panic: magic_len: %"IVdf, (IV)i);

==== //depot/perl/pod/perlapi.pod#221 (text+w) ====
Index: perl/pod/perlapi.pod
--- perl/pod/perlapi.pod#220~24728~     Tue Jun  7 06:15:45 2005
+++ perl/pod/perlapi.pod        Tue Jun  7 07:35:25 2005
@@ -5325,6 +5325,8 @@
 not mean 'a string that contains code points above 0x7F encoded in UTF-8'
 because a valid ASCII string is a valid UTF-8 string.
 
+See also is_utf8_string_loclen() and is_utf8_string_loc().
+
        bool    is_utf8_string(const U8 *s, STRLEN len)
 
 =for hackers
@@ -5332,10 +5334,27 @@
 
 =item is_utf8_string_loc
 
-Like is_ut8_string but store the location of the failure in
-the last argument.
+Like is_ut8_string() but stores the location of the failure (in the
+case of "utf8ness failure") or the location s+len (in the case of
+"utf8ness success") in the C<ep>.
+
+See also is_utf8_string_loclen() and is_utf8_string().
 
        bool    is_utf8_string_loc(const U8 *s, STRLEN len, const U8 **p)
+
+=for hackers
+Found in file utf8.c
+
+=item is_utf8_string_loclen
+
+Like is_ut8_string() but stores the location of the failure (in the
+case of "utf8ness failure") or the location s+len (in the case of
+"utf8ness success") in the C<ep>, and the number of UTF-8
+encoded characters in the C<el>.
+
+See also is_utf8_string_loc() and is_utf8_string().
+
+       bool    is_utf8_string_loclen(const U8 *s, STRLEN len, const U8 **ep, 
STRLEN *el)
 
 =for hackers
 Found in file utf8.c

==== //depot/perl/proto.h#540 (text+w) ====
Index: perl/proto.h
--- perl/proto.h#539~24706~     Sat Jun  4 09:55:27 2005
+++ perl/proto.h        Tue Jun  7 07:35:25 2005
@@ -620,8 +620,10 @@
                        __attribute__nonnull__(pTHX_1);
 
 PERL_CALLCONV bool     Perl_is_utf8_string_loc(pTHX_ const U8 *s, STRLEN len, 
const U8 **p)
-                       __attribute__nonnull__(pTHX_1)
-                       __attribute__nonnull__(pTHX_3);
+                       __attribute__nonnull__(pTHX_1);
+
+PERL_CALLCONV bool     Perl_is_utf8_string_loclen(pTHX_ const U8 *s, STRLEN 
len, const U8 **ep, STRLEN *el)
+                       __attribute__nonnull__(pTHX_1);
 
 PERL_CALLCONV bool     Perl_is_utf8_alnum(pTHX_ const U8 *p)
                        __attribute__warn_unused_result__

==== //depot/perl/utf8.c#236 (text) ====
Index: perl/utf8.c
--- perl/utf8.c#235~24707~      Sat Jun  4 20:55:11 2005
+++ perl/utf8.c Tue Jun  7 07:35:25 2005
@@ -240,10 +240,9 @@
 STRLEN
 Perl_is_utf8_char(pTHX_ const U8 *s)
 {
-    STRLEN len;
+    STRLEN len = UTF8SKIP(s);
 #ifdef IS_UTF8_CHAR
-    len = UTF8SKIP(s);
-    if (len <= 4)
+    if (IS_UTF8_CHAR_FAST(len))
         return IS_UTF8_CHAR(s, len) ? len : 0;
 #endif /* #ifdef IS_UTF8_CHAR */
     return is_utf8_char_slow(s, len);
@@ -257,6 +256,8 @@
 not mean 'a string that contains code points above 0x7F encoded in UTF-8'
 because a valid ASCII string is a valid UTF-8 string.
 
+See also is_utf8_string_loclen() and is_utf8_string_loc().
+
 =cut
 */
 
@@ -276,26 +277,26 @@
         if (UTF8_IS_INVARIANT(*x))
              c = 1;
         else if (!UTF8_IS_START(*x))
-             return FALSE;
+            goto out;
         else {
              /* ... and call is_utf8_char() only if really needed. */
 #ifdef IS_UTF8_CHAR
             c = UTF8SKIP(x);
-            if (c <= 4) {
-                if (!IS_UTF8_CHAR(x, c))
-                    return FALSE;
-            } else {
-                if (!is_utf8_char_slow(x, c))
-                    return FALSE;
-            }
+            if (IS_UTF8_CHAR_FAST(c)) {
+                if (!IS_UTF8_CHAR(x, c))
+                    goto out;
+            } else if (!is_utf8_char_slow(x, c))
+                goto out;
 #else
             c = is_utf8_char(x);
 #endif /* #ifdef IS_UTF8_CHAR */
              if (!c)
-                  return FALSE;
+                 goto out;
         }
         x += c;
     }
+
+ out:
     if (x != send)
        return FALSE;
 
@@ -303,16 +304,20 @@
 }
 
 /*
-=for apidoc A|bool|is_utf8_string_loc|const U8 *s|STRLEN len|const U8 **p
+=for apidoc A|bool|is_utf8_string_loclen|const U8 *s|STRLEN len|const U8 
**ep|const STRLEN *el
 
-Like is_ut8_string but store the location of the failure in
-the last argument.
+Like is_ut8_string() but stores the location of the failure (in the
+case of "utf8ness failure") or the location s+len (in the case of
+"utf8ness success") in the C<ep>, and the number of UTF-8
+encoded characters in the C<el>.
+
+See also is_utf8_string_loc() and is_utf8_string().
 
 =cut
 */
 
 bool
-Perl_is_utf8_string_loc(pTHX_ const U8 *s, STRLEN len, const U8 **p)
+Perl_is_utf8_string_loclen(pTHX_ const U8 *s, STRLEN len, const U8 **ep, 
STRLEN *el)
 {
     const U8* x = s;
     const U8* send;
@@ -321,34 +326,60 @@
     if (!len && s)
         len = strlen((const char *)s);
     send = s + len;
+    if (el)
+        *el = 0;
 
     while (x < send) {
         /* Inline the easy bits of is_utf8_char() here for speed... */
         if (UTF8_IS_INVARIANT(*x))
-             c = 1;
-        else if (!UTF8_IS_START(*x)) {
-             if (p)
-                 *p = x;
-             return FALSE;
-        }
+            c = 1;
+        else if (!UTF8_IS_START(*x))
+            goto out;
         else {
-             /* ... and call is_utf8_char() only if really needed. */
-             c = is_utf8_char(x);
-             if (!c) {
-                  if (p)
-                     *p = x;
-                  return FALSE;
-             }
+            /* ... and call is_utf8_char() only if really needed. */
+#ifdef IS_UTF8_CHAR
+            c = UTF8SKIP(x);
+            if (IS_UTF8_CHAR_FAST(c)) {
+                if (!IS_UTF8_CHAR(x, c))
+                    c = 0;
+            } else
+                c = is_utf8_char_slow(x, c);
+#else
+            c = is_utf8_char(x);
+#endif /* #ifdef IS_UTF8_CHAR */
+            if (!c)
+                goto out;
         }
-        x += c;
+         x += c;
+        if (el)
+            (*el)++;
     }
-    if (x != send) {
-       if (p)
-          *p = x;
+
+ out:
+    if (ep)
+        *ep = x;
+    if (x != send)
        return FALSE;
-    }
 
     return TRUE;
+}
+
+/*
+=for apidoc A|bool|is_utf8_string_loc|const U8 *s|STRLEN len|const U8 
**ep|const STRLEN *el
+
+Like is_ut8_string() but stores the location of the failure (in the
+case of "utf8ness failure") or the location s+len (in the case of
+"utf8ness success") in the C<ep>.
+
+See also is_utf8_string_loclen() and is_utf8_string().
+
+=cut
+*/
+
+bool
+Perl_is_utf8_string_loc(pTHX_ const U8 *s, STRLEN len, const U8 **ep)
+{
+    return is_utf8_string_loclen(s, len, ep, 0);
 }
 
 /*

==== //depot/perl/utf8.h#69 (text) ====
Index: perl/utf8.h
--- perl/utf8.h#68~24687~       Fri Jun  3 01:08:25 2005
+++ perl/utf8.h Tue Jun  7 07:35:25 2005
@@ -327,3 +327,5 @@
         (n) == 3 ? IS_UTF8_CHAR_3(p) : \
         (n) == 4 ? IS_UTF8_CHAR_4(p) : 0)
 
+#define IS_UTF8_CHAR_FAST(n) ((n) <= 4)
+
End of Patch.

Reply via email to