diff options
Diffstat (limited to 'Source/WebCore/css/CSSPrimitiveValue.cpp')
-rw-r--r-- | Source/WebCore/css/CSSPrimitiveValue.cpp | 103 |
1 files changed, 5 insertions, 98 deletions
diff --git a/Source/WebCore/css/CSSPrimitiveValue.cpp b/Source/WebCore/css/CSSPrimitiveValue.cpp index 6d930bd..04f1089 100644 --- a/Source/WebCore/css/CSSPrimitiveValue.cpp +++ b/Source/WebCore/css/CSSPrimitiveValue.cpp @@ -87,103 +87,6 @@ static CSSTextCache& cssTextCache() return cache; } -// A more stylish solution than sharing would be to turn CSSPrimitiveValue (or CSSValues in general) into non-virtual, -// non-refcounted simple type with value semantics. In practice these sharing tricks get similar memory benefits -// with less need for refactoring. - -inline PassRefPtr<CSSPrimitiveValue> CSSPrimitiveValue::createUncachedIdentifier(int identifier) -{ - return adoptRef(new CSSPrimitiveValue(identifier)); -} - -inline PassRefPtr<CSSPrimitiveValue> CSSPrimitiveValue::createUncachedColor(unsigned rgbValue) -{ - return adoptRef(new CSSPrimitiveValue(rgbValue)); -} - -inline PassRefPtr<CSSPrimitiveValue> CSSPrimitiveValue::createUncached(double value, UnitTypes type) -{ - return adoptRef(new CSSPrimitiveValue(value, type)); -} - -PassRefPtr<CSSPrimitiveValue> CSSPrimitiveValue::createIdentifier(int ident) -{ - static RefPtr<CSSPrimitiveValue>* identValueCache = new RefPtr<CSSPrimitiveValue>[numCSSValueKeywords]; - if (ident >= 0 && ident < numCSSValueKeywords) { - RefPtr<CSSPrimitiveValue> primitiveValue = identValueCache[ident]; - if (!primitiveValue) { - primitiveValue = createUncachedIdentifier(ident); - identValueCache[ident] = primitiveValue; - } - return primitiveValue.release(); - } - return createUncachedIdentifier(ident); -} - -PassRefPtr<CSSPrimitiveValue> CSSPrimitiveValue::createColor(unsigned rgbValue) -{ - typedef HashMap<unsigned, RefPtr<CSSPrimitiveValue> > ColorValueCache; - static ColorValueCache* colorValueCache = new ColorValueCache; - // These are the empty and deleted values of the hash table. - if (rgbValue == Color::transparent) { - static CSSPrimitiveValue* colorTransparent = createUncachedColor(Color::transparent).releaseRef(); -#if CPU(ARM) && OS(LINUX) - // A workaround for gcc bug on ARM. - if (!colorTransparent) - return 0; -#endif - return colorTransparent; - } - if (rgbValue == Color::white) { - static CSSPrimitiveValue* colorWhite = createUncachedColor(Color::white).releaseRef(); -#if CPU(ARM) && OS(LINUX) - // A workaround for gcc bug on ARM. - if (!colorWhite) - return 0; -#endif - return colorWhite; - } - RefPtr<CSSPrimitiveValue> primitiveValue = colorValueCache->get(rgbValue); - if (primitiveValue) - return primitiveValue.release(); - primitiveValue = createUncachedColor(rgbValue); - // Just wipe out the cache and start rebuilding when it gets too big. - const int maxColorCacheSize = 512; - if (colorValueCache->size() >= maxColorCacheSize) - colorValueCache->clear(); - colorValueCache->add(rgbValue, primitiveValue); - - return primitiveValue.release(); -} - -PassRefPtr<CSSPrimitiveValue> CSSPrimitiveValue::create(double value, UnitTypes type) -{ - // Small integers are very common. Try to share them. - const int cachedIntegerCount = 128; - // Other common primitive types have UnitTypes smaller than this. - const int maxCachedUnitType = CSS_PX; - typedef RefPtr<CSSPrimitiveValue>(* IntegerValueCache)[maxCachedUnitType + 1]; - static IntegerValueCache integerValueCache = new RefPtr<CSSPrimitiveValue>[cachedIntegerCount][maxCachedUnitType + 1]; - if (type <= maxCachedUnitType && value >= 0 && value < cachedIntegerCount) { - int intValue = static_cast<int>(value); - if (value == intValue) { - RefPtr<CSSPrimitiveValue> primitiveValue = integerValueCache[intValue][type]; - if (!primitiveValue) { - primitiveValue = createUncached(value, type); - integerValueCache[intValue][type] = primitiveValue; - } - return primitiveValue.release(); - } - } - - return createUncached(value, type); -} - -PassRefPtr<CSSPrimitiveValue> CSSPrimitiveValue::create(const String& value, UnitTypes type) -{ - return adoptRef(new CSSPrimitiveValue(value, type)); -} - static const AtomicString& valueOrPropertyName(int valueOrPropertyID) { ASSERT_ARG(valueOrPropertyID, valueOrPropertyID >= 0); @@ -270,7 +173,6 @@ CSSPrimitiveValue::CSSPrimitiveValue(const Length& length) m_value.num = length.percent(); break; case Relative: - case Static: ASSERT_NOT_REACHED(); break; } @@ -809,6 +711,11 @@ String CSSPrimitiveValue::cssText() const text = String::adopt(result); break; } + case CSS_COUNTER_NAME: + text = "counter("; + text += m_value.string; + text += ")"; + break; case CSS_COUNTER: text = "counter("; text += String::number(m_value.num); |