factor out FP heavy code in utf8_mg_pos_cache_update
authorDaniel Dragan <bulk88@hotmail.com>
Fri, 19 Sep 2014 00:32:20 +0000 (20:32 -0400)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 20 Sep 2014 14:43:23 +0000 (07:43 -0700)
Visual C 2003 and 6 couldn't factor this FP math heavy expression out
with -O1, and it appeared twice in machine code, so do it by hand.

sv.c

diff --git a/sv.c b/sv.c
index 04c2826..09c6c58 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -7403,38 +7403,35 @@ S_utf8_mg_pos_cache_update(pTHX_ SV *const sv, MAGIC **const mgp, const STRLEN b
                 cache[1] = byte;
            }
        }
-       else if (byte > cache[3]) {
-           /* New position is between the existing pair of pairs.  */
-           const float keep_earlier
-               = THREEWAY_SQUARE(0, cache[3], byte, blen);
-           const float keep_later
-               = THREEWAY_SQUARE(0, byte, cache[1], blen);
-
-           if (keep_later < keep_earlier) {
-                cache[2] = utf8;
-                cache[3] = byte;
-           }
-           else {
-                cache[0] = utf8;
-                cache[1] = byte;
-           }
-       }
        else {
-           /* New position is before the existing pair of pairs.  */
-           const float keep_earlier
-               = THREEWAY_SQUARE(0, byte, cache[3], blen);
-           const float keep_later
-               = THREEWAY_SQUARE(0, byte, cache[1], blen);
-
-           if (keep_later < keep_earlier) {
-                cache[2] = utf8;
-                cache[3] = byte;
+           const float keep_later = THREEWAY_SQUARE(0, byte, cache[1], blen);
+           if (byte > cache[3]) {
+               /* New position is between the existing pair of pairs.  */
+               const float keep_earlier
+                   = THREEWAY_SQUARE(0, cache[3], byte, blen);
+               if (keep_later < keep_earlier) {
+                   cache[2] = utf8;
+                   cache[3] = byte;
+               }
+               else {
+                   cache[0] = utf8;
+                   cache[1] = byte;
+               }
            }
            else {
-                cache[0] = cache[2];
-                cache[1] = cache[3];
-                cache[2] = utf8;
-                cache[3] = byte;
+               /* 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[2] = utf8;
+                   cache[3] = byte;
+               }
+               else {
+                   cache[0] = cache[2];
+                   cache[1] = cache[3];
+                   cache[2] = utf8;
+                   cache[3] = byte;
+               }
            }
        }
     }