| 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 25 matching lines...) Expand all Loading... |
| 36 { | 36 { |
| 37 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<CSSValuePool>, pool, (adoptPtrWil
lBeNoop(new CSSValuePool()))); | 37 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<CSSValuePool>, pool, (adoptPtrWil
lBeNoop(new CSSValuePool()))); |
| 38 return *pool; | 38 return *pool; |
| 39 } | 39 } |
| 40 | 40 |
| 41 CSSValuePool::CSSValuePool() | 41 CSSValuePool::CSSValuePool() |
| 42 : m_inheritedValue(CSSInheritedValue::create()) | 42 : m_inheritedValue(CSSInheritedValue::create()) |
| 43 , m_implicitInitialValue(CSSInitialValue::createImplicit()) | 43 , m_implicitInitialValue(CSSInitialValue::createImplicit()) |
| 44 , m_explicitInitialValue(CSSInitialValue::createExplicit()) | 44 , m_explicitInitialValue(CSSInitialValue::createExplicit()) |
| 45 , m_unsetValue(CSSUnsetValue::create()) | 45 , m_unsetValue(CSSUnsetValue::create()) |
| 46 , m_colorTransparent(CSSPrimitiveValue::createColor(Color::transparent)) | 46 , m_colorTransparent(CSSColorValue::create(Color::transparent)) |
| 47 , m_colorWhite(CSSPrimitiveValue::createColor(Color::white)) | 47 , m_colorWhite(CSSColorValue::create(Color::white)) |
| 48 , m_colorBlack(CSSPrimitiveValue::createColor(Color::black)) | 48 , m_colorBlack(CSSColorValue::create(Color::black)) |
| 49 { | 49 { |
| 50 m_identifierValueCache.resize(numCSSValueKeywords); | 50 m_identifierValueCache.resize(numCSSValueKeywords); |
| 51 m_pixelValueCache.resize(maximumCacheableIntegerValue + 1); | 51 m_pixelValueCache.resize(maximumCacheableIntegerValue + 1); |
| 52 m_percentValueCache.resize(maximumCacheableIntegerValue + 1); | 52 m_percentValueCache.resize(maximumCacheableIntegerValue + 1); |
| 53 m_numberValueCache.resize(maximumCacheableIntegerValue + 1); | 53 m_numberValueCache.resize(maximumCacheableIntegerValue + 1); |
| 54 } | 54 } |
| 55 | 55 |
| 56 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CS
SValueID ident) | 56 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CS
SValueID ident) |
| 57 { | 57 { |
| 58 if (ident <= 0) | 58 if (ident <= 0) |
| 59 return CSSPrimitiveValue::createIdentifier(ident); | 59 return CSSPrimitiveValue::createIdentifier(ident); |
| 60 | 60 |
| 61 if (!m_identifierValueCache[ident]) | 61 if (!m_identifierValueCache[ident]) |
| 62 m_identifierValueCache[ident] = CSSPrimitiveValue::createIdentifier(iden
t); | 62 m_identifierValueCache[ident] = CSSPrimitiveValue::createIdentifier(iden
t); |
| 63 return m_identifierValueCache[ident]; | 63 return m_identifierValueCache[ident]; |
| 64 } | 64 } |
| 65 | 65 |
| 66 PassRefPtrWillBeRawPtr<CSSCustomIdentValue> CSSValuePool::createIdentifierValue(
CSSPropertyID ident) | 66 PassRefPtrWillBeRawPtr<CSSCustomIdentValue> CSSValuePool::createIdentifierValue(
CSSPropertyID ident) |
| 67 { | 67 { |
| 68 return CSSCustomIdentValue::create(ident); | 68 return CSSCustomIdentValue::create(ident); |
| 69 } | 69 } |
| 70 | 70 |
| 71 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createColorValue(unsigne
d rgbValue) | 71 PassRefPtrWillBeRawPtr<CSSColorValue> CSSValuePool::createColorValue(RGBA32 rgbV
alue) |
| 72 { | 72 { |
| 73 // These are the empty and deleted values of the hash table. | 73 // These are the empty and deleted values of the hash table. |
| 74 if (rgbValue == Color::transparent) | 74 if (rgbValue == Color::transparent) |
| 75 return m_colorTransparent; | 75 return m_colorTransparent; |
| 76 if (rgbValue == Color::white) | 76 if (rgbValue == Color::white) |
| 77 return m_colorWhite; | 77 return m_colorWhite; |
| 78 // Just because it is common. | 78 // Just because it is common. |
| 79 if (rgbValue == Color::black) | 79 if (rgbValue == Color::black) |
| 80 return m_colorBlack; | 80 return m_colorBlack; |
| 81 | 81 |
| 82 // Just wipe out the cache and start rebuilding if it gets too big. | 82 // Just wipe out the cache and start rebuilding if it gets too big. |
| 83 const unsigned maximumColorCacheSize = 512; | 83 const unsigned maximumColorCacheSize = 512; |
| 84 if (m_colorValueCache.size() > maximumColorCacheSize) | 84 if (m_colorValueCache.size() > maximumColorCacheSize) |
| 85 m_colorValueCache.clear(); | 85 m_colorValueCache.clear(); |
| 86 | 86 |
| 87 RefPtrWillBeRawPtr<CSSPrimitiveValue> dummyValue = nullptr; | 87 RefPtrWillBeRawPtr<CSSColorValue> dummyValue = nullptr; |
| 88 ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, dummyValu
e); | 88 ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, dummyValu
e); |
| 89 if (entry.isNewEntry) | 89 if (entry.isNewEntry) |
| 90 entry.storedValue->value = CSSPrimitiveValue::createColor(rgbValue); | 90 entry.storedValue->value = CSSColorValue::create(rgbValue); |
| 91 return entry.storedValue->value; | 91 return entry.storedValue->value; |
| 92 } | 92 } |
| 93 | 93 |
| 94 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createValue(double value
, CSSPrimitiveValue::UnitType type) | 94 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createValue(double value
, CSSPrimitiveValue::UnitType type) |
| 95 { | 95 { |
| 96 if (std::isinf(value)) | 96 if (std::isinf(value)) |
| 97 value = 0; | 97 value = 0; |
| 98 | 98 |
| 99 if (value < 0 || value > maximumCacheableIntegerValue) | 99 if (value < 0 || value > maximumCacheableIntegerValue) |
| 100 return CSSPrimitiveValue::create(value, type); | 100 return CSSPrimitiveValue::create(value, type); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 visitor->trace(m_colorBlack); | 164 visitor->trace(m_colorBlack); |
| 165 visitor->trace(m_pixelValueCache); | 165 visitor->trace(m_pixelValueCache); |
| 166 visitor->trace(m_percentValueCache); | 166 visitor->trace(m_percentValueCache); |
| 167 visitor->trace(m_numberValueCache); | 167 visitor->trace(m_numberValueCache); |
| 168 visitor->trace(m_fontFaceValueCache); | 168 visitor->trace(m_fontFaceValueCache); |
| 169 visitor->trace(m_fontFamilyValueCache); | 169 visitor->trace(m_fontFamilyValueCache); |
| 170 #endif | 170 #endif |
| 171 } | 171 } |
| 172 | 172 |
| 173 } | 173 } |
| OLD | NEW |