diff options
author | Robert Phillips <robertphillips@google.com> | 2017-11-08 15:24:31 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-11-08 21:00:37 +0000 |
commit | f8e2502819499894dff40c4f2f46e46edda15507 (patch) | |
tree | 7fe8c9c6e191f9d393abc8d29ffa1d4146db302d /src/core/SkTMultiMap.h | |
parent | 065b41dd90782e22b5708c8b43696db641d54f46 (diff) |
Prepare to enable explicit gpu resource allocation (take 2)
Change-Id: I3fd78d53e8bea84c0217b9fe6e180eaa9e4ac753
Reviewed-on: https://skia-review.googlesource.com/68920
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/core/SkTMultiMap.h')
-rw-r--r-- | src/core/SkTMultiMap.h | 51 |
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 |