This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
more factoring out in S_utf8_mg_pos_cache_update
authorDaniel Dragan <bulk88@hotmail.com>
Fri, 19 Sep 2014 21:43:11 +0000 (17:43 -0400)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 20 Sep 2014 14:43:23 +0000 (07:43 -0700)
Flip the inputs to keep_earlier, this way one 1 copy of the keep_earlier
three way square exists in machine code. Removing the float casts would
make the calculation more efficient since truncating precsion asm op dont
have to happen after every calculation but I'm not sure about side effects.
Float casts are from commit ab455f6077 with no background provided.

sv.c

diff --git a/sv.c b/sv.c
index c0d4fdb..566c0e6 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -7375,6 +7375,7 @@ S_utf8_mg_pos_cache_update(pTHX_ SV *const sv, MAGIC **const mgp, const STRLEN b
            cache[3] = byte;
        }
     } else {
+/* float casts necessary? XXX */
 #define THREEWAY_SQUARE(a,b,c,d) \
            ((float)((d) - (c))) * ((float)((d) - (c))) \
            + ((float)((c) - (b))) * ((float)((c) - (b))) \
@@ -7401,10 +7402,18 @@ S_utf8_mg_pos_cache_update(pTHX_ SV *const sv, MAGIC **const mgp, const STRLEN b
        }
        else {
            const float keep_later = THREEWAY_SQUARE(0, byte, cache[1], blen);
+           float b, c, keep_earlier;
            if (byte > cache[3]) {
                /* New position is between the existing pair of pairs.  */
-               const float keep_earlier
-                   = THREEWAY_SQUARE(0, cache[3], byte, blen);
+               b = cache[3];
+               c = byte;
+           } else {
+               /* New position is before the existing pair of pairs.  */
+               b = byte;
+               c = cache[3];
+           }
+           keep_earlier = THREEWAY_SQUARE(0, b, c, blen);
+           if (byte > cache[3]) {
                if (keep_later < keep_earlier) {
                    cache[2] = utf8;
                    cache[3] = byte;
@@ -7415,9 +7424,6 @@ S_utf8_mg_pos_cache_update(pTHX_ SV *const sv, MAGIC **const mgp, const STRLEN b
                }
            }
            else {
-               /* New position is before the existing pair of pairs.  */
-               const float keep_earlier
-                   = THREEWAY_SQUARE(0, byte, cache[3], blen);
                if (! (keep_later < keep_earlier)) {
                    cache[0] = cache[2];
                    cache[1] = cache[3];