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

Side by Side Diff: src/core/SkTHashCache.h

Issue 395203002: Revert of Reopened: Caching the result of readPixelsSupported (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 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 unified diff | Download patch
« no previous file with comments | « gyp/tests.gypi ('k') | src/gpu/gl/GrGLCaps.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkTHASHCACHE_DEFINED
9 #define SkTHASHCACHE_DEFINED
10
11 #include "SkTypes.h"
12 #include "SkTDynamicHash.h"
13
14 template <typename T,
15 typename Key,
16 typename Traits = T,
17 int kGrowPercent = 75 >
18 class SkTHashCache : public SkNoncopyable {
19 public:
20
21 SkTHashCache() {
22 this->reset();
23 }
24
25 ~SkTHashCache() {
26 this->clear();
27 }
28
29 T* find(const Key& key) const {
30 return fDict->find(key);
31 }
32
33 /**
34 * If element already in cache, return immediately the cached value
35 */
36 T& add(const T& add) {
37 Key key = Traits::GetKey(add);
38 if (T* val = this->find(key)) {
39 return *val;
40 }
41
42 T* element = SkNEW_ARGS(T, (add));
43
44 fDict->add(element);
45
46 return *element;
47 }
48
49 int size() const {
50 return fDict->count();
51 }
52
53 void reset() {
54 this->clear();
55
56 fDict.reset(SkNEW(DictType));
57 }
58
59 private:
60 typedef SkTDynamicHash<T, Key, Traits, kGrowPercent> DictType;
61
62 void clear() {
63 if (fDict.get()) {
64 typename DictType::Iter it(fDict.get());
65
66 while (!it.done()) {
67 SkDELETE(&(*it));
68 ++it;
69 }
70 }
71 }
72
73 SkAutoTDelete<DictType> fDict;
74 };
75
76 #endif /* SkHASHCACHE_DEFINED */
77
OLDNEW
« no previous file with comments | « gyp/tests.gypi ('k') | src/gpu/gl/GrGLCaps.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698