Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Unified Diff: src/core/SkPathMeasure.cpp

Issue 1037653002: use custom search for pathmeasure (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPathMeasure.cpp
diff --git a/src/core/SkPathMeasure.cpp b/src/core/SkPathMeasure.cpp
index 9d1607532655ddea061104da37b07d683ddb666b..c963e9cf356df10868cf98be3daee42b03d2926a 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];
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698