OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkUrlDataManager_DEFINED | 8 #ifndef SkUrlDataManager_DEFINED |
9 #define SkUrlDataManager_DEFINED | 9 #define SkUrlDataManager_DEFINED |
10 | 10 |
11 #include "SkChecksum.h" | |
12 #include "SkData.h" | 11 #include "SkData.h" |
| 12 #include "SkOpts.h" |
13 #include "SkString.h" | 13 #include "SkString.h" |
14 #include "SkTDynamicHash.h" | 14 #include "SkTDynamicHash.h" |
15 | 15 |
16 /* | 16 /* |
17 * A simple class which allows clients to add opaque data types, and returns a u
rl where this data | 17 * A simple class which allows clients to add opaque data types, and returns a u
rl where this data |
18 * will be hosted. Its up to the owner of this class to actually serve the data
. | 18 * will be hosted. Its up to the owner of this class to actually serve the data
. |
19 */ | 19 */ |
20 bool operator==(const SkData& a, const SkData& b); | 20 bool operator==(const SkData& a, const SkData& b); |
21 | 21 |
22 class UrlDataManager { | 22 class UrlDataManager { |
(...skipping 22 matching lines...) Expand all Loading... |
45 void reset(); | 45 void reset(); |
46 | 46 |
47 private: | 47 private: |
48 struct LookupTrait { | 48 struct LookupTrait { |
49 // We use the data as a hash, this is not really optimal but is fine unt
il proven otherwise | 49 // We use the data as a hash, this is not really optimal but is fine unt
il proven otherwise |
50 static const SkData& GetKey(const UrlData& data) { | 50 static const SkData& GetKey(const UrlData& data) { |
51 return *data.fData.get(); | 51 return *data.fData.get(); |
52 } | 52 } |
53 | 53 |
54 static uint32_t Hash(const SkData& key) { | 54 static uint32_t Hash(const SkData& key) { |
55 return SkChecksum::Murmur3(key.bytes(), key.size()); | 55 return SkOpts::hash(key.bytes(), key.size()); |
56 } | 56 } |
57 }; | 57 }; |
58 | 58 |
59 struct ReverseLookupTrait { | 59 struct ReverseLookupTrait { |
60 static const SkString& GetKey(const UrlData& data) { | 60 static const SkString& GetKey(const UrlData& data) { |
61 return data.fUrl; | 61 return data.fUrl; |
62 } | 62 } |
63 | 63 |
64 static uint32_t Hash(const SkString& key) { | 64 static uint32_t Hash(const SkString& key) { |
65 return SkChecksum::Murmur3(key.c_str(), strlen(key.c_str())); | 65 return SkOpts::hash(key.c_str(), strlen(key.c_str())); |
66 } | 66 } |
67 }; | 67 }; |
68 | 68 |
69 | 69 |
70 SkString fRootUrl; | 70 SkString fRootUrl; |
71 SkTDynamicHash<UrlData, SkData, LookupTrait> fCache; | 71 SkTDynamicHash<UrlData, SkData, LookupTrait> fCache; |
72 SkTDynamicHash<UrlData, SkString, ReverseLookupTrait> fUrlLookup; | 72 SkTDynamicHash<UrlData, SkString, ReverseLookupTrait> fUrlLookup; |
73 uint32_t fDataId; | 73 uint32_t fDataId; |
74 }; | 74 }; |
75 | 75 |
76 #endif | 76 #endif |
OLD | NEW |