From: Subhransu Mohanty Date: Wed, 12 Aug 2020 04:51:09 +0000 (+0900) Subject: optimization: optimize VBezier::length() X-Git-Tag: submit/tizen/20200817.223215~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ebc4defb9c9c39c7ceedd3b099b3686e1498b736;p=platform%2Fcore%2Fuifw%2Flottie-player.git optimization: optimize VBezier::length() - force VLine::length() function to be inline. --- diff --git a/src/vector/vbezier.cpp b/src/vector/vbezier.cpp index 08498c3..797d564 100644 --- a/src/vector/vbezier.cpp +++ b/src/vector/vbezier.cpp @@ -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; diff --git a/src/vector/vline.h b/src/vector/vline.h index cb8d9bf..ee8b4a5 100644 --- a/src/vector/vline.h +++ b/src/vector/vline.h @@ -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;