| OLD | NEW |
| 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 Loading... |
| 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); | |
| 60 } | 56 } |
| 61 | 57 |
| 62 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CS
SValueID ident) | 58 PassRefPtr<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CSSValueID ide
nt) |
| 63 { | 59 { |
| 64 if (ident <= 0) | 60 if (ident <= 0) |
| 65 return CSSPrimitiveValue::createIdentifier(ident); | 61 return CSSPrimitiveValue::createIdentifier(ident); |
| 66 | 62 |
| 67 if (!m_identifierValueCache[ident]) | 63 if (!m_identifierValueCache[ident]) |
| 68 m_identifierValueCache[ident] = CSSPrimitiveValue::createIdentifier(iden
t); | 64 m_identifierValueCache[ident] = CSSPrimitiveValue::createIdentifier(iden
t); |
| 69 return m_identifierValueCache[ident]; | 65 return m_identifierValueCache[ident]; |
| 70 } | 66 } |
| 71 | 67 |
| 72 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CS
SPropertyID ident) | 68 PassRefPtr<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CSSPropertyID
ident) |
| 73 { | 69 { |
| 74 return CSSPrimitiveValue::createIdentifier(ident); | 70 return CSSPrimitiveValue::createIdentifier(ident); |
| 75 } | 71 } |
| 76 | 72 |
| 77 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createColorValue(unsigne
d rgbValue) | 73 PassRefPtr<CSSPrimitiveValue> CSSValuePool::createColorValue(unsigned rgbValue) |
| 78 { | 74 { |
| 79 // These are the empty and deleted values of the hash table. | 75 // These are the empty and deleted values of the hash table. |
| 80 if (rgbValue == Color::transparent) | 76 if (rgbValue == Color::transparent) |
| 81 return m_colorTransparent; | 77 return m_colorTransparent; |
| 82 if (rgbValue == Color::white) | 78 if (rgbValue == Color::white) |
| 83 return m_colorWhite; | 79 return m_colorWhite; |
| 84 // Just because it is common. | 80 // Just because it is common. |
| 85 if (rgbValue == Color::black) | 81 if (rgbValue == Color::black) |
| 86 return m_colorBlack; | 82 return m_colorBlack; |
| 87 | 83 |
| 88 // Just wipe out the cache and start rebuilding if it gets too big. | 84 // Just wipe out the cache and start rebuilding if it gets too big. |
| 89 const unsigned maximumColorCacheSize = 512; | 85 const unsigned maximumColorCacheSize = 512; |
| 90 if (m_colorValueCache.size() > maximumColorCacheSize) | 86 if (m_colorValueCache.size() > maximumColorCacheSize) |
| 91 m_colorValueCache.clear(); | 87 m_colorValueCache.clear(); |
| 92 | 88 |
| 93 RefPtrWillBeRawPtr<CSSPrimitiveValue> dummyValue; | 89 RefPtr<CSSPrimitiveValue> dummyValue; |
| 94 ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, dummyValu
e); | 90 ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, dummyValu
e); |
| 95 if (entry.isNewEntry) | 91 if (entry.isNewEntry) |
| 96 entry.iterator->value = CSSPrimitiveValue::createColor(rgbValue); | 92 entry.iterator->value = CSSPrimitiveValue::createColor(rgbValue); |
| 97 return entry.iterator->value; | 93 return entry.iterator->value; |
| 98 } | 94 } |
| 99 | 95 |
| 100 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createValue(double value
, CSSPrimitiveValue::UnitTypes type) | 96 PassRefPtr<CSSPrimitiveValue> CSSValuePool::createValue(double value, CSSPrimiti
veValue::UnitTypes type) |
| 101 { | 97 { |
| 102 if (value < 0 || value > maximumCacheableIntegerValue) | 98 if (value < 0 || value > maximumCacheableIntegerValue) |
| 103 return CSSPrimitiveValue::create(value, type); | 99 return CSSPrimitiveValue::create(value, type); |
| 104 | 100 |
| 105 int intValue = static_cast<int>(value); | 101 int intValue = static_cast<int>(value); |
| 106 if (value != intValue) | 102 if (value != intValue) |
| 107 return CSSPrimitiveValue::create(value, type); | 103 return CSSPrimitiveValue::create(value, type); |
| 108 | 104 |
| 105 RefPtr<CSSPrimitiveValue>* cache; |
| 109 switch (type) { | 106 switch (type) { |
| 110 case CSSPrimitiveValue::CSS_PX: | 107 case CSSPrimitiveValue::CSS_PX: |
| 111 if (!m_pixelValueCache[intValue]) | 108 cache = m_pixelValueCache; |
| 112 m_pixelValueCache[intValue] = CSSPrimitiveValue::create(value, type)
; | 109 break; |
| 113 return m_pixelValueCache[intValue]; | |
| 114 case CSSPrimitiveValue::CSS_PERCENTAGE: | 110 case CSSPrimitiveValue::CSS_PERCENTAGE: |
| 115 if (!m_percentValueCache[intValue]) | 111 cache = m_percentValueCache; |
| 116 m_percentValueCache[intValue] = CSSPrimitiveValue::create(value, typ
e); | 112 break; |
| 117 return m_percentValueCache[intValue]; | |
| 118 case CSSPrimitiveValue::CSS_NUMBER: | 113 case CSSPrimitiveValue::CSS_NUMBER: |
| 119 if (!m_numberValueCache[intValue]) | 114 cache = m_numberValueCache; |
| 120 m_numberValueCache[intValue] = CSSPrimitiveValue::create(value, type
); | 115 break; |
| 121 return m_numberValueCache[intValue]; | |
| 122 default: | 116 default: |
| 123 return CSSPrimitiveValue::create(value, type); | 117 return CSSPrimitiveValue::create(value, type); |
| 124 } | 118 } |
| 119 |
| 120 if (!cache[intValue]) |
| 121 cache[intValue] = CSSPrimitiveValue::create(value, type); |
| 122 return cache[intValue]; |
| 125 } | 123 } |
| 126 | 124 |
| 127 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createValue(const Length
& value, const RenderStyle& style) | 125 PassRefPtr<CSSPrimitiveValue> CSSValuePool::createValue(const Length& value, con
st RenderStyle& style) |
| 128 { | 126 { |
| 129 return CSSPrimitiveValue::create(value, style.effectiveZoom()); | 127 return CSSPrimitiveValue::create(value, style.effectiveZoom()); |
| 130 } | 128 } |
| 131 | 129 |
| 132 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createFontFamilyValue(co
nst String& familyName) | 130 PassRefPtr<CSSPrimitiveValue> CSSValuePool::createFontFamilyValue(const String&
familyName) |
| 133 { | 131 { |
| 134 RefPtrWillBeMember<CSSPrimitiveValue>& value = m_fontFamilyValueCache.add(fa
milyName, 0).iterator->value; | 132 RefPtr<CSSPrimitiveValue>& value = m_fontFamilyValueCache.add(familyName, 0)
.iterator->value; |
| 135 if (!value) | 133 if (!value) |
| 136 value = CSSPrimitiveValue::create(familyName, CSSPrimitiveValue::CSS_STR
ING); | 134 value = CSSPrimitiveValue::create(familyName, CSSPrimitiveValue::CSS_STR
ING); |
| 137 return value; | 135 return value; |
| 138 } | 136 } |
| 139 | 137 |
| 140 PassRefPtrWillBeRawPtr<CSSValueList> CSSValuePool::createFontFaceValue(const Ato
micString& string) | 138 PassRefPtrWillBeRawPtr<CSSValueList> CSSValuePool::createFontFaceValue(const Ato
micString& string) |
| 141 { | 139 { |
| 142 // Just wipe out the cache and start rebuilding if it gets too big. | 140 // Just wipe out the cache and start rebuilding if it gets too big. |
| 143 const unsigned maximumFontFaceCacheSize = 128; | 141 const unsigned maximumFontFaceCacheSize = 128; |
| 144 if (m_fontFaceValueCache.size() > maximumFontFaceCacheSize) | 142 if (m_fontFaceValueCache.size() > maximumFontFaceCacheSize) |
| 145 m_fontFaceValueCache.clear(); | 143 m_fontFaceValueCache.clear(); |
| 146 | 144 |
| 147 RefPtrWillBeMember<CSSValueList>& value = m_fontFaceValueCache.add(string, 0
).iterator->value; | 145 RefPtrWillBeMember<CSSValueList>& value = m_fontFaceValueCache.add(string, 0
).iterator->value; |
| 148 if (!value) | 146 if (!value) |
| 149 value = BisonCSSParser::parseFontFaceValue(string); | 147 value = BisonCSSParser::parseFontFaceValue(string); |
| 150 return value; | 148 return value; |
| 151 } | 149 } |
| 152 | 150 |
| 153 void CSSValuePool::trace(Visitor* visitor) | 151 void CSSValuePool::trace(Visitor* visitor) |
| 154 { | 152 { |
| 155 visitor->trace(m_inheritedValue); | 153 visitor->trace(m_inheritedValue); |
| 156 visitor->trace(m_implicitInitialValue); | 154 visitor->trace(m_implicitInitialValue); |
| 157 visitor->trace(m_explicitInitialValue); | 155 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); | |
| 166 visitor->trace(m_fontFaceValueCache); | 156 visitor->trace(m_fontFaceValueCache); |
| 167 visitor->trace(m_fontFamilyValueCache); | |
| 168 } | 157 } |
| 169 | 158 |
| 170 } | 159 } |
| OLD | NEW |