aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkPathMeasure.cpp
diff options
context:
space:
mode:
authorGravatar reed <reed@chromium.org>2015-03-26 04:13:08 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-03-26 04:13:08 -0700
commit83e22e407e48acc4e23774edb2241c6a111e1db9 (patch)
tree0cd266a16d8b17b8c64460af63878334eb79979f /src/core/SkPathMeasure.cpp
parent36352bf5e38f45a70ee4f4fc132a38048d38206d (diff)
use custom search for pathmeasure
Diffstat (limited to 'src/core/SkPathMeasure.cpp')
-rw-r--r--src/core/SkPathMeasure.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/core/SkPathMeasure.cpp b/src/core/SkPathMeasure.cpp
index 9d16075326..c963e9cf35 100644
--- a/src/core/SkPathMeasure.cpp
+++ b/src/core/SkPathMeasure.cpp
@@ -442,6 +442,36 @@ SkScalar SkPathMeasure::getLength() {
return fLength;
}
+template <typename T, typename K>
+int SkTKSearch(const T base[], int count, const K& key) {
+ SkASSERT(count >= 0);
+ if (count <= 0) {
+ return ~0;
+ }
+
+ SkASSERT(base != NULL); // base may be NULL if count is zero
+
+ int lo = 0;
+ int hi = count - 1;
+
+ while (lo < hi) {
+ int mid = (hi + lo) >> 1;
+ if (base[mid].fDistance < key) {
+ lo = mid + 1;
+ } else {
+ hi = mid;
+ }
+ }
+
+ if (base[hi].fDistance < key) {
+ hi += 1;
+ hi = ~hi;
+ } else if (key < base[hi].fDistance) {
+ hi = ~hi;
+ }
+ return hi;
+}
+
const SkPathMeasure::Segment* SkPathMeasure::distanceToSegment(
SkScalar distance, SkScalar* t) {
SkDEBUGCODE(SkScalar length = ) this->getLength();
@@ -450,7 +480,7 @@ const SkPathMeasure::Segment* SkPathMeasure::distanceToSegment(
const Segment* seg = fSegments.begin();
int count = fSegments.count();
- int index = SkTSearch<SkScalar>(&seg->fDistance, count, distance, sizeof(Segment));
+ int index = SkTKSearch<Segment, SkScalar>(seg, count, distance);
// don't care if we hit an exact match or not, so we xor index if it is negative
index ^= (index >> 31);
seg = &seg[index];