aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkTMultiMap.h
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-11-08 13:34:43 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-11-08 19:06:17 +0000
commitf290376736b42a19b87da78c6ba2558313896860 (patch)
tree664ff0fb2802069f4373238a6127b287cc3db8a6 /src/core/SkTMultiMap.h
parent47ba5cd0974273192c83cc27addb9ae1880c1d6d (diff)
Prepare to enable explicit gpu resource allocation
Change-Id: I407e45711c61831febbac3d3d3a88e3fdde92c5f Reviewed-on: https://skia-review.googlesource.com/68212 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/core/SkTMultiMap.h')
-rw-r--r--src/core/SkTMultiMap.h51
1 files changed, 37 insertions, 14 deletions
diff --git a/src/core/SkTMultiMap.h b/src/core/SkTMultiMap.h
index 3d6e38e454..987a306661 100644
--- a/src/core/SkTMultiMap.h
+++ b/src/core/SkTMultiMap.h
@@ -34,6 +34,7 @@ public:
for ( ; !iter.done(); ++iter) {
ValueList* next;
for (ValueList* cur = &(*iter); cur; cur = next) {
+ HashTraits::OnFree(cur->fValue);
next = cur->fNext;
delete cur;
}
@@ -69,20 +70,7 @@ public:
list = list->fNext;
}
- if (list->fNext) {
- ValueList* next = list->fNext;
- list->fValue = next->fValue;
- list->fNext = next->fNext;
- delete next;
- } else if (prev) {
- prev->fNext = nullptr;
- delete list;
- } else {
- fHash.remove(key);
- delete list;
- }
-
- --fCount;
+ this->internalRemove(prev, list, key);
}
T* find(const Key& key) const {
@@ -105,6 +93,23 @@ public:
return nullptr;
}
+ template<class FindPredicate>
+ T* findAndRemove(const Key& key, const FindPredicate f) {
+ ValueList* list = fHash.find(key);
+
+ ValueList* prev = nullptr;
+ while (list) {
+ if (f(list->fValue)){
+ T* value = list->fValue;
+ this->internalRemove(prev, list, key);
+ return value;
+ }
+ prev = list;
+ list = list->fNext;
+ }
+ return nullptr;
+ }
+
int count() const { return fCount; }
#ifdef SK_DEBUG
@@ -168,6 +173,24 @@ public:
private:
SkTDynamicHash<ValueList, Key> fHash;
int fCount;
+
+ void internalRemove(ValueList* prev, ValueList* elem, const Key& key) {
+ if (elem->fNext) {
+ ValueList* next = elem->fNext;
+ elem->fValue = next->fValue;
+ elem->fNext = next->fNext;
+ delete next;
+ } else if (prev) {
+ prev->fNext = nullptr;
+ delete elem;
+ } else {
+ fHash.remove(key);
+ delete elem;
+ }
+
+ --fCount;
+ }
+
};
#endif