From 2cf6c8816a73e0132bd8fa3b509d62d7c51b6e47 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 7 May 2012 11:21:11 +0200 Subject: Imported WebKit commit 7e538425aa020340619e927792f3d895061fb54b (http://svn.webkit.org/repository/webkit/trunk@116286) --- Source/WebCore/css/CSSValuePool.cpp | 66 +++++++++++++++---------------------- 1 file changed, 27 insertions(+), 39 deletions(-) (limited to 'Source/WebCore/css/CSSValuePool.cpp') diff --git a/Source/WebCore/css/CSSValuePool.cpp b/Source/WebCore/css/CSSValuePool.cpp index c46c7047c..ce757b933 100644 --- a/Source/WebCore/css/CSSValuePool.cpp +++ b/Source/WebCore/css/CSSValuePool.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 Apple Inc. All rights reserved. + * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,11 +27,18 @@ #include "CSSValuePool.h" #include "CSSParser.h" +#include "CSSStyleSheet.h" #include "CSSValueKeywords.h" #include "CSSValueList.h" namespace WebCore { +CSSValuePool& cssValuePool() +{ + DEFINE_STATIC_LOCAL(CSSValuePool, pool, ()); + return pool; +} + CSSValuePool::CSSValuePool() : m_inheritedValue(CSSInheritedValue::create()) , m_implicitInitialValue(CSSInitialValue::createImplicit()) @@ -39,13 +46,6 @@ CSSValuePool::CSSValuePool() , m_colorTransparent(CSSPrimitiveValue::createColor(Color::transparent)) , m_colorWhite(CSSPrimitiveValue::createColor(Color::white)) , m_colorBlack(CSSPrimitiveValue::createColor(Color::black)) - , m_pixelZero(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)) - , m_percentZero(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PERCENTAGE)) - , m_numberZero(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_NUMBER)) -{ -} - -CSSValuePool::~CSSValuePool() { } @@ -54,11 +54,9 @@ PassRefPtr CSSValuePool::createIdentifierValue(int ident) if (ident <= 0 || ident >= numCSSValueKeywords) return CSSPrimitiveValue::createIdentifier(ident); - RefPtr dummyValue; - pair entry = m_identifierValueCache.add(ident, dummyValue); - if (entry.second) - entry.first->second = CSSPrimitiveValue::createIdentifier(ident); - return entry.first->second; + if (!m_identifierValueCache[ident]) + m_identifierValueCache[ident] = CSSPrimitiveValue::createIdentifier(ident); + return m_identifierValueCache[ident]; } PassRefPtr CSSValuePool::createColorValue(unsigned rgbValue) @@ -78,69 +76,59 @@ PassRefPtr CSSValuePool::createColorValue(unsigned rgbValue) m_colorValueCache.clear(); RefPtr dummyValue; - pair entry = m_colorValueCache.add(rgbValue, dummyValue); - if (entry.second) - entry.first->second = CSSPrimitiveValue::createColor(rgbValue); - return entry.first->second; + ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, dummyValue); + if (entry.isNewEntry) + entry.iterator->second = CSSPrimitiveValue::createColor(rgbValue); + return entry.iterator->second; } PassRefPtr CSSValuePool::createValue(double value, CSSPrimitiveValue::UnitTypes type) { - // Small positive integers repeat often. - static const int maximumCacheableValue = 256; - if (value < 0 || value > maximumCacheableValue) + if (value < 0 || value > maximumCacheableIntegerValue) return CSSPrimitiveValue::create(value, type); int intValue = static_cast(value); if (value != intValue) return CSSPrimitiveValue::create(value, type); - IntegerValueCache* cache; + RefPtr* cache; switch (type) { case CSSPrimitiveValue::CSS_PX: - if (intValue == 0) - return m_pixelZero; - cache = &m_pixelValueCache; + cache = m_pixelValueCache; break; case CSSPrimitiveValue::CSS_PERCENTAGE: - if (intValue == 0) - return m_percentZero; - cache = &m_percentValueCache; + cache = m_percentValueCache; break; case CSSPrimitiveValue::CSS_NUMBER: - if (intValue == 0) - return m_numberZero; - cache = &m_numberValueCache; + cache = m_numberValueCache; break; default: return CSSPrimitiveValue::create(value, type); } - RefPtr dummyValue; - pair entry = cache->add(intValue, dummyValue); - if (entry.second) - entry.first->second = CSSPrimitiveValue::create(value, type); - return entry.first->second; + if (!cache[intValue]) + cache[intValue] = CSSPrimitiveValue::create(value, type); + return cache[intValue]; } PassRefPtr CSSValuePool::createFontFamilyValue(const String& familyName) { - RefPtr& value = m_fontFamilyValueCache.add(familyName, 0).first->second; + RefPtr& value = m_fontFamilyValueCache.add(familyName, 0).iterator->second; if (!value) value = CSSPrimitiveValue::create(familyName, CSSPrimitiveValue::CSS_STRING); return value; } -PassRefPtr CSSValuePool::createFontFaceValue(const AtomicString& string, CSSStyleSheet* contextStyleSheet) +PassRefPtr CSSValuePool::createFontFaceValue(const AtomicString& string) { // Just wipe out the cache and start rebuilding if it gets too big. const int maximumFontFaceCacheSize = 128; if (m_fontFaceValueCache.size() > maximumFontFaceCacheSize) m_fontFaceValueCache.clear(); - RefPtr& value = m_fontFaceValueCache.add(string, 0).first->second; + RefPtr& value = m_fontFaceValueCache.add(string, 0).iterator->second; if (!value) - value = CSSParser::parseFontFaceValue(string, contextStyleSheet); + value = CSSParser::parseFontFaceValue(string); return value; } -- cgit v1.2.1