Add all new static functions to embed.fnc
authorNicholas Clark <nick@ccl4.org>
Thu, 23 Mar 2006 11:33:48 +0000 (11:33 +0000)
committerNicholas Clark <nick@ccl4.org>
Thu, 23 Mar 2006 11:33:48 +0000 (11:33 +0000)
Remove old unused static functions.
Remove references to cache[2] and cache[3].

p4raw-id: //depot/perl@27580

embed.fnc
embed.h
proto.h
sv.c

index 46ccb40..2f86df3 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -1353,13 +1353,18 @@ s       |int    |sv_2iuv_non_preserve   |NN SV *sv|I32 numtype
 #  endif
 sR     |I32    |expect_number  |NN char** pattern
 #
-s      |bool   |utf8_mg_pos    |NN SV *sv|NN MAGIC **mgp|NN STRLEN **cachep \
-                               |I32 i|NN I32 *offsetp|I32 uoff \
-                               |NN const U8 **sp|NN const U8 *start \
-                               |NN const U8 *send
-s      |bool   |utf8_mg_pos_init       |NN SV *sv|NN MAGIC **mgp \
-                               |NN STRLEN **cachep|I32 i|I32 offsetp \
-                               |NN const U8 *s|NN const U8 *start
+s      |STRLEN |sv_pos_u2b_forwards|NN const U8 *const start \
+               |NN const U8 *const send|STRLEN uoffset
+s      |STRLEN |sv_pos_u2b_midway|NN const U8 *const start \
+               |NN const U8 *const send|STRLEN uoffset|STRLEN uend
+s      |STRLEN |sv_pos_u2b_cached|NN SV *sv|NN MAGIC **mgp \
+               |NN const U8 *const start|NN const U8 *const send \
+               |STRLEN uoffset|STRLEN uoffset0|STRLEN boffset0
+s      |void   |utf8_mg_pos_cache_update|NN SV *sv|NN MAGIC **mgp \
+               |STRLEN byte|STRLEN utf8
+s      |STRLEN |sv_pos_b2u_forwards|NN const U8 *s|NN const U8 *const target
+s      |STRLEN |sv_pos_b2u_midway|NN const U8 *s|NN const U8 *const target \
+               |NN const U8 *end|STRLEN endu
 s      |char * |stringify_regexp|NN SV *sv|NN MAGIC *mg|NULLOK STRLEN *lp
 sn     |char * |F0convert      |NV nv|NN char *endbuf|NN STRLEN *len
 #  if defined(PERL_OLD_COPY_ON_WRITE)
diff --git a/embed.h b/embed.h
index eb21c52..4ff4ebb 100644 (file)
--- a/embed.h
+++ b/embed.h
 #define expect_number          S_expect_number
 #endif
 #ifdef PERL_CORE
-#define utf8_mg_pos            S_utf8_mg_pos
-#define utf8_mg_pos_init       S_utf8_mg_pos_init
+#define sv_pos_u2b_forwards    S_sv_pos_u2b_forwards
+#define sv_pos_u2b_midway      S_sv_pos_u2b_midway
+#define sv_pos_u2b_cached      S_sv_pos_u2b_cached
+#define utf8_mg_pos_cache_update       S_utf8_mg_pos_cache_update
+#define sv_pos_b2u_forwards    S_sv_pos_b2u_forwards
+#define sv_pos_b2u_midway      S_sv_pos_b2u_midway
 #define stringify_regexp       S_stringify_regexp
 #define F0convert              S_F0convert
 #endif
 #define expect_number(a)       S_expect_number(aTHX_ a)
 #endif
 #ifdef PERL_CORE
-#define utf8_mg_pos(a,b,c,d,e,f,g,h,i) S_utf8_mg_pos(aTHX_ a,b,c,d,e,f,g,h,i)
-#define utf8_mg_pos_init(a,b,c,d,e,f,g)        S_utf8_mg_pos_init(aTHX_ a,b,c,d,e,f,g)
+#define sv_pos_u2b_forwards(a,b,c)     S_sv_pos_u2b_forwards(aTHX_ a,b,c)
+#define sv_pos_u2b_midway(a,b,c,d)     S_sv_pos_u2b_midway(aTHX_ a,b,c,d)
+#define sv_pos_u2b_cached(a,b,c,d,e,f,g)       S_sv_pos_u2b_cached(aTHX_ a,b,c,d,e,f,g)
+#define utf8_mg_pos_cache_update(a,b,c,d)      S_utf8_mg_pos_cache_update(aTHX_ a,b,c,d)
+#define sv_pos_b2u_forwards(a,b)       S_sv_pos_b2u_forwards(aTHX_ a,b)
+#define sv_pos_b2u_midway(a,b,c,d)     S_sv_pos_b2u_midway(aTHX_ a,b,c,d)
 #define stringify_regexp(a,b,c)        S_stringify_regexp(aTHX_ a,b,c)
 #define F0convert              S_F0convert
 #endif
diff --git a/proto.h b/proto.h
index b84c409..568466a 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -3711,21 +3711,32 @@ STATIC I32      S_expect_number(pTHX_ char** pattern)
                        __attribute__nonnull__(pTHX_1);
 
 #
-STATIC bool    S_utf8_mg_pos(pTHX_ SV *sv, MAGIC **mgp, STRLEN **cachep, I32 i, I32 *offsetp, I32 uoff, const U8 **sp, const U8 *start, const U8 *send)
+STATIC STRLEN  S_sv_pos_u2b_forwards(pTHX_ const U8 *const start, const U8 *const send, STRLEN uoffset)
+                       __attribute__nonnull__(pTHX_1)
+                       __attribute__nonnull__(pTHX_2);
+
+STATIC STRLEN  S_sv_pos_u2b_midway(pTHX_ const U8 *const start, const U8 *const send, STRLEN uoffset, STRLEN uend)
+                       __attribute__nonnull__(pTHX_1)
+                       __attribute__nonnull__(pTHX_2);
+
+STATIC STRLEN  S_sv_pos_u2b_cached(pTHX_ SV *sv, MAGIC **mgp, const U8 *const start, const U8 *const send, STRLEN uoffset, STRLEN uoffset0, STRLEN boffset0)
                        __attribute__nonnull__(pTHX_1)
                        __attribute__nonnull__(pTHX_2)
                        __attribute__nonnull__(pTHX_3)
-                       __attribute__nonnull__(pTHX_5)
-                       __attribute__nonnull__(pTHX_7)
-                       __attribute__nonnull__(pTHX_8)
-                       __attribute__nonnull__(pTHX_9);
+                       __attribute__nonnull__(pTHX_4);
+
+STATIC void    S_utf8_mg_pos_cache_update(pTHX_ SV *sv, MAGIC **mgp, STRLEN byte, STRLEN utf8)
+                       __attribute__nonnull__(pTHX_1)
+                       __attribute__nonnull__(pTHX_2);
+
+STATIC STRLEN  S_sv_pos_b2u_forwards(pTHX_ const U8 *s, const U8 *const target)
+                       __attribute__nonnull__(pTHX_1)
+                       __attribute__nonnull__(pTHX_2);
 
-STATIC bool    S_utf8_mg_pos_init(pTHX_ SV *sv, MAGIC **mgp, STRLEN **cachep, I32 i, I32 offsetp, const U8 *s, const U8 *start)
+STATIC STRLEN  S_sv_pos_b2u_midway(pTHX_ const U8 *s, const U8 *const target, const U8 *end, STRLEN endu)
                        __attribute__nonnull__(pTHX_1)
                        __attribute__nonnull__(pTHX_2)
-                       __attribute__nonnull__(pTHX_3)
-                       __attribute__nonnull__(pTHX_6)
-                       __attribute__nonnull__(pTHX_7);
+                       __attribute__nonnull__(pTHX_3);
 
 STATIC char *  S_stringify_regexp(pTHX_ SV *sv, MAGIC *mg, STRLEN *lp)
                        __attribute__nonnull__(pTHX_1)
diff --git a/sv.c b/sv.c
index 6661670..01fe6e5 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -5332,163 +5332,6 @@ Perl_sv_len_utf8(pTHX_ register SV *sv)
     }
 }
 
-/* S_utf8_mg_pos_init() is used to initialize the mg_ptr field of
- * a PERL_UTF8_magic.  The mg_ptr is used to store the mapping
- * between UTF-8 and byte offsets.  There are two (substr offset and substr
- * length, the i offset, PERL_MAGIC_UTF8_CACHESIZE) times two (UTF-8 offset
- * and byte offset) cache positions.
- *
- * The mg_len field is used by sv_len_utf8(), see its comments.
- * Note that the mg_len is not the length of the mg_ptr field.
- *
- */
-STATIC bool
-S_utf8_mg_pos_init(pTHX_ SV *sv, MAGIC **mgp, STRLEN **cachep, I32 i,
-                  I32 offsetp, const U8 *s, const U8 *start)
-{
-    bool found = FALSE;
-
-    if (SvMAGICAL(sv) && !SvREADONLY(sv)) {
-       if (!*mgp) {
-           *mgp = sv_magicext(sv, 0, PERL_MAGIC_utf8, (MGVTBL*)&PL_vtbl_utf8, 0, 0);
-           (*mgp)->mg_len = -1;
-       }
-       assert(*mgp);
-
-       if ((*mgp)->mg_ptr)
-           *cachep = (STRLEN *) (*mgp)->mg_ptr;
-       else {
-           Newxz(*cachep, PERL_MAGIC_UTF8_CACHESIZE * 2, STRLEN);
-           (*mgp)->mg_ptr = (char *) *cachep;
-       }
-       assert(*cachep);
-
-       (*cachep)[i]   = offsetp;
-       (*cachep)[i+1] = s - start;
-       found = TRUE;
-    }
-
-    return found;
-}
-
-/*
- * S_utf8_mg_pos() is used to query and update mg_ptr field of
- * a PERL_UTF8_magic.  The mg_ptr is used to store the mapping
- * between UTF-8 and byte offsets.  See also the comments of
- * S_utf8_mg_pos_init().
- *
- */
-STATIC bool
-S_utf8_mg_pos(pTHX_ SV *sv, MAGIC **mgp, STRLEN **cachep, I32 i, I32 *offsetp, I32 uoff, const U8 **sp, const U8 *start, const U8 *send)
-{
-    bool found = FALSE;
-
-    if (SvMAGICAL(sv) && !SvREADONLY(sv)) {
-       if (!*mgp)
-           *mgp = mg_find(sv, PERL_MAGIC_utf8);
-       if (*mgp && (*mgp)->mg_ptr) {
-           *cachep = (STRLEN *) (*mgp)->mg_ptr;
-           ASSERT_UTF8_CACHE(*cachep);
-           if ((*cachep)[i] == (STRLEN)uoff)   /* An exact match. */
-                 found = TRUE;
-           else {                      /* We will skip to the right spot. */
-                STRLEN forw  = 0;
-                STRLEN backw = 0;
-                const U8* p = NULL;
-
-                /* The assumption is that going backward is half
-                 * the speed of going forward (that's where the
-                 * 2 * backw in the below comes from).  (The real
-                 * figure of course depends on the UTF-8 data.) */
-
-                if ((*cachep)[i] > (STRLEN)uoff) {
-                     forw  = uoff;
-                     backw = (*cachep)[i] - (STRLEN)uoff;
-
-                     if (forw < 2 * backw)
-                          p = start;
-                     else
-                          p = start + (*cachep)[i+1];
-                }
-                /* Try this only for the substr offset (i == 0),
-                 * not for the substr length (i == 2). */
-                else if (i == 0) { /* (*cachep)[i] < uoff */
-                     const STRLEN ulen = sv_len_utf8(sv);
-
-                     if ((STRLEN)uoff < ulen) {
-                          forw  = (STRLEN)uoff - (*cachep)[i];
-                          backw = ulen - (STRLEN)uoff;
-
-                          if (forw < 2 * backw)
-                               p = start + (*cachep)[i+1];
-                          else
-                               p = send;
-                     }
-
-                     /* If the string is not long enough for uoff,
-                      * we could extend it, but not at this low a level. */
-                }
-
-                if (p) {
-                     if (forw < 2 * backw) {
-                          while (forw--)
-                               p += UTF8SKIP(p);
-                     }
-                     else {
-                          while (backw--) {
-                               p--;
-                               while (UTF8_IS_CONTINUATION(*p))
-                                    p--;
-                          }
-                     }
-
-                     /* Update the cache. */
-                     (*cachep)[i]   = (STRLEN)uoff;
-                     (*cachep)[i+1] = p - start;
-
-                     /* Drop the stale "length" cache */
-                     if (i == 0) {
-                         (*cachep)[2] = 0;
-                         (*cachep)[3] = 0;
-                     }
-
-                     found = TRUE;
-                }
-           }
-           if (found) {        /* Setup the return values. */
-                *offsetp = (*cachep)[i+1];
-                *sp = start + *offsetp;
-                if (*sp >= send) {
-                     *sp = send;
-                     *offsetp = send - start;
-                }
-                else if (*sp < start) {
-                     *sp = start;
-                     *offsetp = 0;
-                }
-           }
-       }
-#ifdef PERL_UTF8_CACHE_ASSERT
-       if (found) {
-            const U8 *s = start;
-            I32 n = uoff;
-
-            while (n-- && s < send)
-                 s += UTF8SKIP(s);
-
-            if (i == 0) {
-                 assert(*offsetp == s - start);
-                 assert((*cachep)[0] == (STRLEN)uoff);
-                 assert((*cachep)[1] == *offsetp);
-            }
-            ASSERT_UTF8_CACHE(*cachep);
-       }
-#endif
-    }
-
-    return found;
-}
-
 /*
 =for apidoc sv_pos_u2b
 
@@ -5508,9 +5351,6 @@ type coercion.
  *
  */
 
-static void
-S_utf8_mg_pos_cache_update(pTHX_ SV *sv, MAGIC **mgp, STRLEN byte, STRLEN utf8);
-
 static STRLEN
 S_sv_pos_u2b_forwards(pTHX_ const U8 *const start, const U8 *const send,
                      STRLEN uoffset)
@@ -5534,7 +5374,7 @@ S_sv_pos_u2b_midway(pTHX_ const U8 *const start, const U8 *send,
 {
     STRLEN backw = uend - uoffset;
     if (uoffset < 2 * backw) {
-       /* The assumption is that going fowards is twice the speed of going
+       /* The assumption is that going forwards is twice the speed of going
           forward (that's where the 2 * backw comes from).
           (The real figure of course depends on the UTF-8 data.)  */
        return S_sv_pos_u2b_forwards(aTHX_ start, send, uoffset);
@@ -5679,14 +5519,10 @@ Handles magic and type coercion.
 /*
  * sv_pos_b2u() uses, like sv_pos_u2b(), the mg_ptr of the potential
  * PERL_UTF8_magic of the sv to store the mapping between UTF-8 and
- * byte offsets.  See also the comments of S_utf8_mg_pos().
+ * byte offsets.
  *
  */
 
-
-static STRLEN
-S_sv_pos_b2u_forwards(pTHX_ const U8 *s, const U8 *const target);
-
 static void
 S_utf8_mg_pos_cache_update(pTHX_ SV *sv, MAGIC **mgp, STRLEN byte, STRLEN utf8)
 {
@@ -5735,8 +5571,6 @@ S_utf8_mg_pos_cache_update(pTHX_ SV *sv, MAGIC **mgp, STRLEN byte, STRLEN utf8)
     cache[1] = byte;
     ASSERT_UTF8_CACHE(cache);
     /* Drop the stale "length" cache */
-    cache[2] = 0;
-    cache[3] = 0;
 }
 
 /* If we don't know the character offset of the end of a region, our only
@@ -5763,8 +5597,8 @@ S_sv_pos_b2u_forwards(pTHX_ const U8 *s, const U8 *const target)
 }
 
 /* We already know all of the way, now we may be able to walk back.  The same
-   assumption is made as in S_utf8_mg_pos(), namely that walking backward is
-   twice slower than walking forward. */
+   assumption is made as in S_sv_pos_u2b_midway(), namely that walking
+   backward is half the speed of walking forward. */
 static STRLEN
 S_sv_pos_b2u_midway(pTHX_ const U8 *s, const U8 *const target, const U8 *end,
                    STRLEN endu)