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

Unified Diff: src/core/SkPathHeap.cpp

Issue 190923002: Add deduping capability to SkPathHeap (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 6 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 | « src/core/SkPathHeap.h ('k') | src/core/SkPictureRecord.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPathHeap.cpp
===================================================================
--- src/core/SkPathHeap.cpp (revision 13690)
+++ src/core/SkPathHeap.cpp (working copy)
@@ -9,6 +9,7 @@
#include "SkPath.h"
#include "SkStream.h"
#include "SkReadBuffer.h"
+#include "SkTSearch.h"
#include "SkWriteBuffer.h"
#include <new>
@@ -49,6 +50,38 @@
return fPaths.count();
}
+SkPathHeap::LookupEntry::LookupEntry(const SkPath& path)
+ : fGenerationID(path.getGenerationID()), fStorageSlot(0) {
+}
+
+SkPathHeap::LookupEntry* SkPathHeap::addIfNotPresent(const SkPath& path) {
+ LookupEntry searchKey(path);
+ int index = SkTSearch<const LookupEntry, LookupEntry::Less>(
+ fLookupTable.begin(),
+ fLookupTable.count(),
+ searchKey,
+ sizeof(LookupEntry));
+ if (index < 0) {
+ index = ~index;
+ *fLookupTable.insert(index) = LookupEntry(path);
+ }
+
+ return &fLookupTable[index];;
+}
+
+int SkPathHeap::insert(const SkPath& path) {
+ SkPathHeap::LookupEntry* entry = this->addIfNotPresent(path);
+
+ if (entry->storageSlot() > 0) {
+ return entry->storageSlot();
+ }
+
+ int newSlot = this->append(path);
+ SkASSERT(newSlot > 0);
+ entry->setStorageSlot(newSlot);
+ return newSlot;
+}
+
void SkPathHeap::flatten(SkWriteBuffer& buffer) const {
int count = fPaths.count();
« no previous file with comments | « src/core/SkPathHeap.h ('k') | src/core/SkPictureRecord.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698