Changeset 77768 in webkit
- Timestamp:
- Feb 6, 2011 8:22:23 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r77766 r77768 1 2011-02-06 Andreas Kling <kling@webkit.org> 2 3 Reviewed by Dirk Schulze. 4 5 Refactor Font::normalizeSpaces() to avoid an extra String copy. 6 https://bugs.webkit.org/show_bug.cgi?id=53871 7 8 Have normalizeSpaces() take UChar*,length arguments instead of a 9 String, since all call sites were creating temporaries from these 10 components anyway. 11 12 Font::normalizeSpaces() now always makes 1 String copy, 13 instead of 1 in the best case and 2 in the worst case. 14 15 * platform/graphics/Font.cpp: 16 (WebCore::Font::normalizeSpaces): 17 * platform/graphics/Font.h: 18 * platform/graphics/qt/FontQt.cpp: 19 (WebCore::drawTextCommon): 20 (WebCore::Font::floatWidthForSimpleText): 21 (WebCore::Font::floatWidthForComplexText): 22 (WebCore::Font::offsetForPositionForSimpleText): 23 (WebCore::Font::offsetForPositionForComplexText): 24 (WebCore::Font::selectionRectForSimpleText): 25 (WebCore::Font::selectionRectForComplexText): 26 * svg/SVGFont.cpp: 27 (WebCore::SVGTextRunWalker::walk): 28 1 29 2011-02-06 Andreas Kling <kling@webkit.org> 2 30 -
trunk/Source/WebCore/platform/graphics/Font.cpp
r77173 r77768 248 248 #endif 249 249 250 String Font::normalizeSpaces(const String& string) 251 { 252 const UChar* characters = string.characters(); 253 unsigned length = string.length(); 254 Vector<UChar, 256> buffer(length); 255 bool didReplacement = false; 256 257 for (unsigned i = 0; i < length; ++i) { 258 UChar originalCharacter = characters[i]; 259 buffer[i] = normalizeSpaces(originalCharacter); 260 if (buffer[i] != originalCharacter) 261 didReplacement = true; 262 } 263 264 return didReplacement ? String(buffer.data(), length) : string; 250 String Font::normalizeSpaces(const UChar* characters, unsigned length) 251 { 252 UChar* buffer; 253 String normalized = String::createUninitialized(length, buffer); 254 255 for (unsigned i = 0; i < length; ++i) 256 buffer[i] = normalizeSpaces(characters[i]); 257 258 return normalized; 265 259 } 266 260 -
trunk/Source/WebCore/platform/graphics/Font.h
r77153 r77768 224 224 } 225 225 226 static String normalizeSpaces(const String&);226 static String normalizeSpaces(const UChar*, unsigned length); 227 227 228 228 #if ENABLE(SVG_FONTS) -
trunk/Source/WebCore/platform/graphics/qt/FontQt.cpp
r76743 r77768 108 108 } 109 109 110 String sanitized = Font::normalizeSpaces( String(run.characters(), run.length()));110 String sanitized = Font::normalizeSpaces(run.characters(), run.length()); 111 111 QString string = fromRawDataWithoutRef(sanitized); 112 112 QPointF pt(point.x(), point.y()); … … 300 300 return 0; 301 301 302 String sanitized = Font::normalizeSpaces( String(run.characters(), run.length()));302 String sanitized = Font::normalizeSpaces(run.characters(), run.length()); 303 303 QString string = fromRawDataWithoutRef(sanitized); 304 304 … … 327 327 return QFontMetrics(font()).width(space) + run.expansion(); 328 328 329 String sanitized = Font::normalizeSpaces( String(run.characters(), run.length()));329 String sanitized = Font::normalizeSpaces(run.characters(), run.length()); 330 330 QString string = fromRawDataWithoutRef(sanitized); 331 331 … … 341 341 { 342 342 #if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) 343 String sanitized = Font::normalizeSpaces( String(run.characters(), run.length()));343 String sanitized = Font::normalizeSpaces(run.characters(), run.length()); 344 344 QString string = fromRawDataWithoutRef(sanitized); 345 345 … … 368 368 int Font::offsetForPositionForComplexText(const TextRun& run, float position, bool) const 369 369 { 370 String sanitized = Font::normalizeSpaces( String(run.characters(), run.length()));370 String sanitized = Font::normalizeSpaces(run.characters(), run.length()); 371 371 QString string = fromRawDataWithoutRef(sanitized); 372 372 … … 379 379 { 380 380 #if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) 381 String sanitized = Font::normalizeSpaces( String(run.characters(), run.length()));381 String sanitized = Font::normalizeSpaces(run.characters(), run.length()); 382 382 QString wholeText = fromRawDataWithoutRef(sanitized); 383 383 QString selectedText = fromRawDataWithoutRef(sanitized, from, qMin(to - from, wholeText.length() - from)); … … 395 395 FloatRect Font::selectionRectForComplexText(const TextRun& run, const FloatPoint& pt, int h, int from, int to) const 396 396 { 397 String sanitized = Font::normalizeSpaces( String(run.characters(), run.length()));397 String sanitized = Font::normalizeSpaces(run.characters(), run.length()); 398 398 QString string = fromRawDataWithoutRef(sanitized); 399 399 -
trunk/Source/WebCore/svg/SVGFont.cpp
r77766 r77768 245 245 ASSERT(0 <= from && from <= to && to - from <= run.length()); 246 246 247 const String text = Font::normalizeSpaces( String(run.data(from), to - from));247 const String text = Font::normalizeSpaces(run.data(from), to - from); 248 248 Vector<SVGGlyphIdentifier::ArabicForm> chars(charactersWithArabicForm(text, run.rtl())); 249 249 … … 275 275 characterLookupRange = endOfScanRange - i; 276 276 277 String lookupString = Font::normalizeSpaces( String(run.data(i), characterLookupRange));277 String lookupString = Font::normalizeSpaces(run.data(i), characterLookupRange); 278 278 279 279 Vector<SVGGlyphIdentifier> glyphs;
Note: See TracChangeset
for help on using the changeset viewer.