OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 24 matching lines...) Expand all Loading... | |
35 #include "platform/fonts/FontPlatformData.h" | 35 #include "platform/fonts/FontPlatformData.h" |
36 #include "wtf/HashMap.h" | 36 #include "wtf/HashMap.h" |
37 #include "wtf/ListHashSet.h" | 37 #include "wtf/ListHashSet.h" |
38 | 38 |
39 namespace blink { | 39 namespace blink { |
40 | 40 |
41 class SimpleFontData; | 41 class SimpleFontData; |
42 | 42 |
43 struct FontDataCacheKeyHash { | 43 struct FontDataCacheKeyHash { |
44 STATIC_ONLY(FontDataCacheKeyHash); | 44 STATIC_ONLY(FontDataCacheKeyHash); |
45 static unsigned hash(const FontPlatformData& platformData) | 45 static unsigned hash(const FontPlatformData* platformData) |
46 { | 46 { |
47 return platformData.hash(); | 47 return platformData->hash(); |
48 } | 48 } |
49 | 49 |
50 static bool equal(const FontPlatformData& a, const FontPlatformData& b) | 50 static bool equal(const FontPlatformData* a, const FontPlatformData* b) |
51 { | 51 { |
52 return a == b; | 52 const FontPlatformData* emptyValue = reinterpret_cast<FontPlatformData*> (-1); |
53 | |
54 if (a == emptyValue) | |
eae
2016/06/06 17:26:53
What's the difference between emptyValue (-1) and
| |
55 return b == emptyValue; | |
56 if (b == emptyValue) | |
57 return a == emptyValue; | |
58 | |
59 if (!a || !b) | |
60 return a == b; | |
61 | |
62 CHECK(a && b); | |
63 | |
64 return *a == *b; | |
53 } | 65 } |
54 | 66 |
55 static const bool safeToCompareToEmptyOrDeleted = true; | 67 static const bool safeToCompareToEmptyOrDeleted = true; |
56 }; | 68 }; |
57 | 69 |
58 struct FontDataCacheKeyTraits : WTF::GenericHashTraits<FontPlatformData> { | |
59 STATIC_ONLY(FontDataCacheKeyTraits); | |
60 static const bool emptyValueIsZero = true; | |
61 static const FontPlatformData& emptyValue() | |
62 { | |
63 DEFINE_STATIC_LOCAL(FontPlatformData, key, (0.f, false, false)); | |
64 return key; | |
65 } | |
66 static void constructDeletedValue(FontPlatformData& slot, bool) | |
67 { | |
68 new (NotNull, &slot) FontPlatformData(WTF::HashTableDeletedValue); | |
69 } | |
70 static bool isDeletedValue(const FontPlatformData& value) | |
71 { | |
72 return value.isHashTableDeletedValue(); | |
73 } | |
74 }; | |
75 | |
76 class FontDataCache { | 70 class FontDataCache { |
77 USING_FAST_MALLOC(FontDataCache); | 71 USING_FAST_MALLOC(FontDataCache); |
78 WTF_MAKE_NONCOPYABLE(FontDataCache); | 72 WTF_MAKE_NONCOPYABLE(FontDataCache); |
79 public: | 73 public: |
80 FontDataCache() { } | 74 FontDataCache() { } |
81 | 75 |
82 PassRefPtr<SimpleFontData> get(const FontPlatformData*, ShouldRetain = Retai n); | 76 PassRefPtr<SimpleFontData> get(const FontPlatformData*, ShouldRetain = Retai n); |
83 bool contains(const FontPlatformData*) const; | 77 bool contains(const FontPlatformData*) const; |
84 void release(const SimpleFontData*); | 78 void release(const SimpleFontData*); |
85 | 79 |
86 // This is used by FontVerticalDataCache to mark all items with vertical dat a | 80 // This is used by FontVerticalDataCache to mark all items with vertical dat a |
87 // that are currently in cache as "in cache", which is later used to sweep t he FontVerticalDataCache. | 81 // that are currently in cache as "in cache", which is later used to sweep t he FontVerticalDataCache. |
88 void markAllVerticalData(); | 82 void markAllVerticalData(); |
89 | 83 |
90 // Purges items in FontDataCache according to provided severity. | 84 // Purges items in FontDataCache according to provided severity. |
91 // Returns true if any removal of cache items actually occurred. | 85 // Returns true if any removal of cache items actually occurred. |
92 bool purge(PurgeSeverity); | 86 bool purge(PurgeSeverity); |
93 | 87 |
94 private: | 88 private: |
95 bool purgeLeastRecentlyUsed(int count); | 89 bool purgeLeastRecentlyUsed(int count); |
96 | 90 |
97 typedef HashMap<FontPlatformData, std::pair<RefPtr<SimpleFontData>, unsigned >, FontDataCacheKeyHash, FontDataCacheKeyTraits> Cache; | 91 typedef HashMap<const FontPlatformData*, std::pair<RefPtr<SimpleFontData>, u nsigned>, FontDataCacheKeyHash> Cache; |
98 Cache m_cache; | 92 Cache m_cache; |
99 ListHashSet<RefPtr<SimpleFontData>> m_inactiveFontData; | 93 ListHashSet<RefPtr<SimpleFontData>> m_inactiveFontData; |
100 }; | 94 }; |
101 | 95 |
102 } // namespace blink | 96 } // namespace blink |
103 | 97 |
104 #endif | 98 #endif |
OLD | NEW |