optimization: optimize VBezier::length()
authorSubhransu Mohanty <sub.mohanty@samsung.com>
Wed, 12 Aug 2020 04:51:09 +0000 (13:51 +0900)
committerJongmin Lee <jm105.lee@samsung.com>
Mon, 17 Aug 2020 22:22:02 +0000 (07:22 +0900)
- force VLine::length() function to be inline.

src/vector/vbezier.cpp
src/vector/vline.h

index 08498c3e5f38e0a5a3b6032d3e6d2bb6f6f05a37..797d56440bd19a8e0dba9c7edfde9fdf764fd0c0 100644 (file)
@@ -43,23 +43,16 @@ VBezier VBezier::fromPoints(const VPointF &p1, const VPointF &p2,
 
 float VBezier::length() const
 {
-    VBezier left, right; /* bez poly splits */
-    float   len = 0.0;   /* arc length */
-    float   chord;       /* chord length */
-    float   length;
+    const auto len = VLine::length(x1, y1, x2, y2) +
+                     VLine::length(x2, y2, x3, y3) +
+                     VLine::length(x3, y3, x4, y4);
 
-    len = len + VLine::length(x1, y1, x2, y2);
-    len = len + VLine::length(x2, y2, x3, y3);
-    len = len + VLine::length(x3, y3, x4, y4);
-
-    chord = VLine::length(x1, y1, x4, y4);
+    const auto chord = VLine::length(x1, y1, x4, y4);
 
     if ((len - chord) > 0.01) {
-        split(&left, &right);    /* split in two */
-        length = left.length() + /* try left side */
-                 right.length(); /* try right side */
-
-        return length;
+        VBezier left, right;
+        split(&left, &right);
+        return left.length() + right.length();
     }
 
     return len;
index cb8d9bffc475ac451ec4645e80f98cbd13395241..ee8b4a567bbd62023102ee3d8ffc3ee9ea214115 100644 (file)
@@ -66,7 +66,7 @@ inline float VLine::angle() const
 // approximate sqrt(x*x + y*y) using alpha max plus beta min algorithm.
 // With alpha = 1, beta = 3/8, giving results with the largest error less
 // than 7% compared to the exact value.
-inline float VLine::length(float x1, float y1, float x2, float y2)
+inline V_ALWAYS_INLINE float VLine::length(float x1, float y1, float x2, float y2)
 {
     float x = x2 - x1;
     float y = y2 - y1;