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

Side by Side Diff: Source/core/css/CSSValuePool.cpp

Issue 148523016: Move most of the [Pass]RefPtr's of CSSPrimitiveValue to our transition types. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 } 46 }
47 47
48 CSSValuePool::CSSValuePool() 48 CSSValuePool::CSSValuePool()
49 : m_inheritedValue(CSSInheritedValue::create()) 49 : m_inheritedValue(CSSInheritedValue::create())
50 , m_implicitInitialValue(CSSInitialValue::createImplicit()) 50 , m_implicitInitialValue(CSSInitialValue::createImplicit())
51 , m_explicitInitialValue(CSSInitialValue::createExplicit()) 51 , m_explicitInitialValue(CSSInitialValue::createExplicit())
52 , m_colorTransparent(CSSPrimitiveValue::createColor(Color::transparent)) 52 , m_colorTransparent(CSSPrimitiveValue::createColor(Color::transparent))
53 , m_colorWhite(CSSPrimitiveValue::createColor(Color::white)) 53 , m_colorWhite(CSSPrimitiveValue::createColor(Color::white))
54 , m_colorBlack(CSSPrimitiveValue::createColor(Color::black)) 54 , m_colorBlack(CSSPrimitiveValue::createColor(Color::black))
55 { 55 {
56 m_identifierValueCache.resize(numCSSValueKeywords);
57 m_pixelValueCache.resize(maximumCacheableIntegerValue + 1);
58 m_percentValueCache.resize(maximumCacheableIntegerValue + 1);
59 m_numberValueCache.resize(maximumCacheableIntegerValue + 1);
haraken 2014/02/12 14:05:45 Do we need these resize()s? I guess that these col
wibling-chromium 2014/02/12 14:42:19 The resize() method initializes the backing memory
56 } 60 }
57 61
58 PassRefPtr<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CSSValueID ide nt) 62 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CS SValueID ident)
59 { 63 {
60 if (ident <= 0) 64 if (ident <= 0)
61 return CSSPrimitiveValue::createIdentifier(ident); 65 return CSSPrimitiveValue::createIdentifier(ident);
62 66
63 if (!m_identifierValueCache[ident]) 67 if (!m_identifierValueCache[ident])
64 m_identifierValueCache[ident] = CSSPrimitiveValue::createIdentifier(iden t); 68 m_identifierValueCache[ident] = CSSPrimitiveValue::createIdentifier(iden t);
65 return m_identifierValueCache[ident]; 69 return m_identifierValueCache[ident];
66 } 70 }
67 71
68 PassRefPtr<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CSSPropertyID ident) 72 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CS SPropertyID ident)
69 { 73 {
70 return CSSPrimitiveValue::createIdentifier(ident); 74 return CSSPrimitiveValue::createIdentifier(ident);
71 } 75 }
72 76
73 PassRefPtr<CSSPrimitiveValue> CSSValuePool::createColorValue(unsigned rgbValue) 77 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createColorValue(unsigne d rgbValue)
74 { 78 {
75 // These are the empty and deleted values of the hash table. 79 // These are the empty and deleted values of the hash table.
76 if (rgbValue == Color::transparent) 80 if (rgbValue == Color::transparent)
77 return m_colorTransparent; 81 return m_colorTransparent;
78 if (rgbValue == Color::white) 82 if (rgbValue == Color::white)
79 return m_colorWhite; 83 return m_colorWhite;
80 // Just because it is common. 84 // Just because it is common.
81 if (rgbValue == Color::black) 85 if (rgbValue == Color::black)
82 return m_colorBlack; 86 return m_colorBlack;
83 87
84 // Just wipe out the cache and start rebuilding if it gets too big. 88 // Just wipe out the cache and start rebuilding if it gets too big.
85 const unsigned maximumColorCacheSize = 512; 89 const unsigned maximumColorCacheSize = 512;
86 if (m_colorValueCache.size() > maximumColorCacheSize) 90 if (m_colorValueCache.size() > maximumColorCacheSize)
87 m_colorValueCache.clear(); 91 m_colorValueCache.clear();
88 92
89 RefPtr<CSSPrimitiveValue> dummyValue; 93 RefPtrWillBeRawPtr<CSSPrimitiveValue> dummyValue;
90 ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, dummyValu e); 94 ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, dummyValu e);
91 if (entry.isNewEntry) 95 if (entry.isNewEntry)
92 entry.iterator->value = CSSPrimitiveValue::createColor(rgbValue); 96 entry.iterator->value = CSSPrimitiveValue::createColor(rgbValue);
93 return entry.iterator->value; 97 return entry.iterator->value;
94 } 98 }
95 99
96 PassRefPtr<CSSPrimitiveValue> CSSValuePool::createValue(double value, CSSPrimiti veValue::UnitTypes type) 100 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createValue(double value , CSSPrimitiveValue::UnitTypes type)
97 { 101 {
98 if (value < 0 || value > maximumCacheableIntegerValue) 102 if (value < 0 || value > maximumCacheableIntegerValue)
99 return CSSPrimitiveValue::create(value, type); 103 return CSSPrimitiveValue::create(value, type);
100 104
101 int intValue = static_cast<int>(value); 105 int intValue = static_cast<int>(value);
102 if (value != intValue) 106 if (value != intValue)
103 return CSSPrimitiveValue::create(value, type); 107 return CSSPrimitiveValue::create(value, type);
104 108
105 RefPtr<CSSPrimitiveValue>* cache;
106 switch (type) { 109 switch (type) {
107 case CSSPrimitiveValue::CSS_PX: 110 case CSSPrimitiveValue::CSS_PX:
108 cache = m_pixelValueCache; 111 if (!m_pixelValueCache[intValue])
109 break; 112 m_pixelValueCache[intValue] = CSSPrimitiveValue::create(value, type) ;
113 return m_pixelValueCache[intValue];
110 case CSSPrimitiveValue::CSS_PERCENTAGE: 114 case CSSPrimitiveValue::CSS_PERCENTAGE:
111 cache = m_percentValueCache; 115 if (!m_percentValueCache[intValue])
112 break; 116 m_percentValueCache[intValue] = CSSPrimitiveValue::create(value, typ e);
117 return m_percentValueCache[intValue];
113 case CSSPrimitiveValue::CSS_NUMBER: 118 case CSSPrimitiveValue::CSS_NUMBER:
114 cache = m_numberValueCache; 119 if (!m_numberValueCache[intValue])
115 break; 120 m_numberValueCache[intValue] = CSSPrimitiveValue::create(value, type );
121 return m_numberValueCache[intValue];
116 default: 122 default:
117 return CSSPrimitiveValue::create(value, type); 123 return CSSPrimitiveValue::create(value, type);
118 } 124 }
119
120 if (!cache[intValue])
121 cache[intValue] = CSSPrimitiveValue::create(value, type);
122 return cache[intValue];
123 } 125 }
124 126
125 PassRefPtr<CSSPrimitiveValue> CSSValuePool::createValue(const Length& value, con st RenderStyle& style) 127 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createValue(const Length & value, const RenderStyle& style)
126 { 128 {
127 return CSSPrimitiveValue::create(value, style.effectiveZoom()); 129 return CSSPrimitiveValue::create(value, style.effectiveZoom());
128 } 130 }
129 131
130 PassRefPtr<CSSPrimitiveValue> CSSValuePool::createFontFamilyValue(const String& familyName) 132 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createFontFamilyValue(co nst String& familyName)
131 { 133 {
132 RefPtr<CSSPrimitiveValue>& value = m_fontFamilyValueCache.add(familyName, 0) .iterator->value; 134 RefPtrWillBeMember<CSSPrimitiveValue>& value = m_fontFamilyValueCache.add(fa milyName, 0).iterator->value;
133 if (!value) 135 if (!value)
134 value = CSSPrimitiveValue::create(familyName, CSSPrimitiveValue::CSS_STR ING); 136 value = CSSPrimitiveValue::create(familyName, CSSPrimitiveValue::CSS_STR ING);
135 return value; 137 return value;
136 } 138 }
137 139
138 PassRefPtrWillBeRawPtr<CSSValueList> CSSValuePool::createFontFaceValue(const Ato micString& string) 140 PassRefPtrWillBeRawPtr<CSSValueList> CSSValuePool::createFontFaceValue(const Ato micString& string)
139 { 141 {
140 // Just wipe out the cache and start rebuilding if it gets too big. 142 // Just wipe out the cache and start rebuilding if it gets too big.
141 const unsigned maximumFontFaceCacheSize = 128; 143 const unsigned maximumFontFaceCacheSize = 128;
142 if (m_fontFaceValueCache.size() > maximumFontFaceCacheSize) 144 if (m_fontFaceValueCache.size() > maximumFontFaceCacheSize)
143 m_fontFaceValueCache.clear(); 145 m_fontFaceValueCache.clear();
144 146
145 RefPtrWillBeMember<CSSValueList>& value = m_fontFaceValueCache.add(string, 0 ).iterator->value; 147 RefPtrWillBeMember<CSSValueList>& value = m_fontFaceValueCache.add(string, 0 ).iterator->value;
146 if (!value) 148 if (!value)
147 value = BisonCSSParser::parseFontFaceValue(string); 149 value = BisonCSSParser::parseFontFaceValue(string);
148 return value; 150 return value;
149 } 151 }
150 152
151 void CSSValuePool::trace(Visitor* visitor) 153 void CSSValuePool::trace(Visitor* visitor)
152 { 154 {
153 visitor->trace(m_inheritedValue); 155 visitor->trace(m_inheritedValue);
154 visitor->trace(m_implicitInitialValue); 156 visitor->trace(m_implicitInitialValue);
155 visitor->trace(m_explicitInitialValue); 157 visitor->trace(m_explicitInitialValue);
158 visitor->trace(m_identifierValueCache);
159 visitor->trace(m_colorValueCache);
160 visitor->trace(m_colorTransparent);
161 visitor->trace(m_colorWhite);
162 visitor->trace(m_colorBlack);
163 visitor->trace(m_pixelValueCache);
164 visitor->trace(m_percentValueCache);
165 visitor->trace(m_numberValueCache);
156 visitor->trace(m_fontFaceValueCache); 166 visitor->trace(m_fontFaceValueCache);
167 visitor->trace(m_fontFamilyValueCache);
157 } 168 }
158 169
159 } 170 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698