Changeset 107919 in webkit
- Timestamp:
- Feb 16, 2012 3:05:24 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r107915 r107919 1 2012-02-15 Andreas Kling <awesomekling@apple.com> 2 3 Share font-family CSS values through CSSValuePool. 4 <http://webkit.org/b/78604> 5 6 Reviewed by Darin Adler. 7 8 Cache and share FontFamilyValue instances in the per-document CSSValuePool. 9 This reduces memory consumption by 248 kB on the Moz page cycler (64-bit) 10 and avoids a bunch of extra work. 11 12 This is a regression from the recent attribute style refactoring; previously 13 the mapped attribute declaration table would ensure that multiple 'font' 14 elements with the same 'face' value would share the same FontFamilyValue. 15 16 We're not yet sharing the entire CSSValueList returned by parseFontFamily() 17 but this is a step on the way there. 18 19 * css/FontFamilyValue.cpp: 20 * css/FontFamilyValue.h: 21 22 Removed appendSpaceSeparated(), making FontFamilyValue immutable. 23 24 * css/CSSParser.cpp: 25 (FontFamilyValueBuilder): 26 (WebCore::FontFamilyValueBuilder::FontFamilyValueBuilder): 27 (WebCore::FontFamilyValueBuilder::add): 28 (WebCore::FontFamilyValueBuilder::commit): 29 (WebCore::CSSParser::parseFontFamily): 30 31 Refactor parseFontFamily() to defer creation of FontFamilyValue until 32 the whole family name is known. Added a little helper class to avoid 33 code duplication. 34 35 * css/CSSValuePool.h: 36 * css/CSSValuePool.cpp: 37 (WebCore::CSSValuePool::createFontFamilyValue): 38 39 Added a FontFamilyValue cache to CSSValuePool. All values are tied to 40 the lifetime of the pool. 41 1 42 2012-02-16 Simon Hausmann <simon.hausmann@nokia.com> 2 43 -
trunk/Source/WebCore/css/CSSParser.cpp
r107899 r107919 4296 4296 } 4297 4297 4298 class FontFamilyValueBuilder { 4299 public: 4300 FontFamilyValueBuilder(CSSValueList* list, CSSValuePool* pool) 4301 : m_list(list) 4302 , m_cssValuePool(pool) 4303 { 4304 } 4305 4306 void add(const CSSParserString& string) 4307 { 4308 if (!m_builder.isEmpty()) 4309 m_builder.append(' '); 4310 m_builder.append(string.characters, string.length); 4311 } 4312 4313 void commit() 4314 { 4315 if (m_builder.isEmpty()) 4316 return; 4317 m_list->append(m_cssValuePool->createFontFamilyValue(m_builder.toString())); 4318 m_builder.clear(); 4319 } 4320 4321 private: 4322 StringBuilder m_builder; 4323 CSSValueList* m_list; 4324 CSSValuePool* m_cssValuePool; 4325 }; 4326 4298 4327 PassRefPtr<CSSValueList> CSSParser::parseFontFamily() 4299 4328 { … … 4301 4330 CSSParserValue* value = m_valueList->current(); 4302 4331 4303 FontFamilyValue* currFamily = 0; 4332 FontFamilyValueBuilder familyBuilder(list.get(), cssValuePool()); 4333 bool inFamily = false; 4334 4304 4335 while (value) { 4305 4336 if (value->id == CSSValueInitial || value->id == CSSValueInherit) … … 4313 4344 4314 4345 if (value->id >= CSSValueSerif && value->id <= CSSValueWebkitBody) { 4315 if ( currFamily)4316 currFamily->appendSpaceSeparated(value->string.characters, value->string.length);4346 if (inFamily) 4347 familyBuilder.add(value->string); 4317 4348 else if (nextValBreaksFont || !nextValIsFontName) 4318 4349 list->append(cssValuePool()->createIdentifierValue(value->id)); 4319 4350 else { 4320 RefPtr<FontFamilyValue> newFamily = FontFamilyValue::create(value->string);4321 currFamily = newFamily.get();4322 list->append(newFamily.release());4351 familyBuilder.commit(); 4352 familyBuilder.add(value->string); 4353 inFamily = true; 4323 4354 } 4324 4355 } else if (value->unit == CSSPrimitiveValue::CSS_STRING) { 4325 4356 // Strings never share in a family name. 4326 currFamily = 0; 4327 list->append(FontFamilyValue::create(value->string)); 4357 inFamily = false; 4358 familyBuilder.commit(); 4359 list->append(cssValuePool()->createFontFamilyValue(value->string)); 4328 4360 } else if (value->unit == CSSPrimitiveValue::CSS_IDENT) { 4329 if ( currFamily)4330 currFamily->appendSpaceSeparated(value->string.characters, value->string.length);4361 if (inFamily) 4362 familyBuilder.add(value->string); 4331 4363 else if (nextValBreaksFont || !nextValIsFontName) 4332 list->append( FontFamilyValue::create(value->string));4364 list->append(cssValuePool()->createFontFamilyValue(value->string)); 4333 4365 else { 4334 RefPtr<FontFamilyValue> newFamily = FontFamilyValue::create(value->string);4335 currFamily = newFamily.get();4336 list->append(newFamily.release());4366 familyBuilder.commit(); 4367 familyBuilder.add(value->string); 4368 inFamily = true; 4337 4369 } 4338 4370 } else { … … 4345 4377 if (nextValBreaksFont) { 4346 4378 value = m_valueList->next(); 4347 currFamily = 0; 4379 familyBuilder.commit(); 4380 inFamily = false; 4348 4381 } 4349 4382 else if (nextValIsFontName) … … 4352 4385 break; 4353 4386 } 4387 familyBuilder.commit(); 4388 4354 4389 if (!list->length()) 4355 4390 list = 0; -
trunk/Source/WebCore/css/CSSValuePool.cpp
r101959 r107919 121 121 } 122 122 123 PassRefPtr<FontFamilyValue> CSSValuePool::createFontFamilyValue(const String& familyName) 124 { 125 RefPtr<FontFamilyValue>& value = m_fontFamilyValueCache.add(familyName, 0).first->second; 126 if (!value) 127 value = FontFamilyValue::create(familyName); 128 return value; 123 129 } 130 131 } -
trunk/Source/WebCore/css/CSSValuePool.h
r101959 r107919 30 30 #include "CSSInitialValue.h" 31 31 #include "CSSPrimitiveValue.h" 32 #include "FontFamilyValue.h" 32 33 #include <wtf/HashMap.h> 33 34 #include <wtf/RefPtr.h> … … 40 41 ~CSSValuePool(); 41 42 43 PassRefPtr<FontFamilyValue> createFontFamilyValue(const String&); 42 44 PassRefPtr<CSSInheritedValue> createInheritedValue() { return m_inheritedValue; } 43 45 PassRefPtr<CSSInitialValue> createImplicitInitialValue() { return m_implicitInitialValue; } … … 72 74 IntegerValueCache m_percentValueCache; 73 75 IntegerValueCache m_numberValueCache; 76 77 typedef HashMap<String, RefPtr<FontFamilyValue> > FontFamilyValueCache; 78 FontFamilyValueCache m_fontFamilyValueCache; 74 79 }; 75 80 -
trunk/Source/WebCore/css/FontFamilyValue.cpp
r99567 r107919 59 59 } 60 60 61 void FontFamilyValue::appendSpaceSeparated(const UChar* characters, unsigned length)62 {63 m_familyName.append(' ');64 m_familyName.append(characters, length);65 }66 67 61 String FontFamilyValue::customCssText() const 68 62 { -
trunk/Source/WebCore/css/FontFamilyValue.h
r99567 r107919 34 34 } 35 35 36 void appendSpaceSeparated(const UChar* characters, unsigned length);37 38 36 const String& familyName() const { return m_familyName; } 39 37
Note: See TracChangeset
for help on using the changeset viewer.