Changeset 77768 in webkit


Ignore:
Timestamp:
Feb 6, 2011 8:22:23 AM (13 years ago)
Author:
andreas.kling@nokia.com
Message:

2011-02-06 Andreas Kling <kling@webkit.org>

Reviewed by Dirk Schulze.

Refactor Font::normalizeSpaces() to avoid an extra String copy.
https://bugs.webkit.org/show_bug.cgi?id=53871

Have normalizeSpaces() take UChar*,length arguments instead of a
String, since all call sites were creating temporaries from these
components anyway.

Font::normalizeSpaces() now always makes 1 String copy,
instead of 1 in the best case and 2 in the worst case.

  • platform/graphics/Font.cpp: (WebCore::Font::normalizeSpaces):
  • platform/graphics/Font.h:
  • platform/graphics/qt/FontQt.cpp: (WebCore::drawTextCommon): (WebCore::Font::floatWidthForSimpleText): (WebCore::Font::floatWidthForComplexText): (WebCore::Font::offsetForPositionForSimpleText): (WebCore::Font::offsetForPositionForComplexText): (WebCore::Font::selectionRectForSimpleText): (WebCore::Font::selectionRectForComplexText):
  • svg/SVGFont.cpp: (WebCore::SVGTextRunWalker::walk):
Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r77766 r77768  
     12011-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
    1292011-02-06  Andreas Kling  <kling@webkit.org>
    230
  • trunk/Source/WebCore/platform/graphics/Font.cpp

    r77173 r77768  
    248248#endif
    249249
    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;
     250String 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;
    265259}
    266260
  • trunk/Source/WebCore/platform/graphics/Font.h

    r77153 r77768  
    224224    }
    225225
    226     static String normalizeSpaces(const String&);
     226    static String normalizeSpaces(const UChar*, unsigned length);
    227227
    228228#if ENABLE(SVG_FONTS)
  • trunk/Source/WebCore/platform/graphics/qt/FontQt.cpp

    r76743 r77768  
    108108    }
    109109
    110     String sanitized = Font::normalizeSpaces(String(run.characters(), run.length()));
     110    String sanitized = Font::normalizeSpaces(run.characters(), run.length());
    111111    QString string = fromRawDataWithoutRef(sanitized);
    112112    QPointF pt(point.x(), point.y());
     
    300300        return 0;
    301301
    302     String sanitized = Font::normalizeSpaces(String(run.characters(), run.length()));
     302    String sanitized = Font::normalizeSpaces(run.characters(), run.length());
    303303    QString string = fromRawDataWithoutRef(sanitized);
    304304
     
    327327        return QFontMetrics(font()).width(space) + run.expansion();
    328328
    329     String sanitized = Font::normalizeSpaces(String(run.characters(), run.length()));
     329    String sanitized = Font::normalizeSpaces(run.characters(), run.length());
    330330    QString string = fromRawDataWithoutRef(sanitized);
    331331
     
    341341{
    342342#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());
    344344    QString string = fromRawDataWithoutRef(sanitized);
    345345
     
    368368int Font::offsetForPositionForComplexText(const TextRun& run, float position, bool) const
    369369{
    370     String sanitized = Font::normalizeSpaces(String(run.characters(), run.length()));
     370    String sanitized = Font::normalizeSpaces(run.characters(), run.length());
    371371    QString string = fromRawDataWithoutRef(sanitized);
    372372
     
    379379{
    380380#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());
    382382    QString wholeText = fromRawDataWithoutRef(sanitized);
    383383    QString selectedText = fromRawDataWithoutRef(sanitized, from, qMin(to - from, wholeText.length() - from));
     
    395395FloatRect Font::selectionRectForComplexText(const TextRun& run, const FloatPoint& pt, int h, int from, int to) const
    396396{
    397     String sanitized = Font::normalizeSpaces(String(run.characters(), run.length()));
     397    String sanitized = Font::normalizeSpaces(run.characters(), run.length());
    398398    QString string = fromRawDataWithoutRef(sanitized);
    399399
  • trunk/Source/WebCore/svg/SVGFont.cpp

    r77766 r77768  
    245245        ASSERT(0 <= from && from <= to && to - from <= run.length());
    246246
    247         const String text = Font::normalizeSpaces(String(run.data(from), to - from));
     247        const String text = Font::normalizeSpaces(run.data(from), to - from);
    248248        Vector<SVGGlyphIdentifier::ArabicForm> chars(charactersWithArabicForm(text, run.rtl()));
    249249
     
    275275            characterLookupRange = endOfScanRange - i;
    276276
    277             String lookupString = Font::normalizeSpaces(String(run.data(i), characterLookupRange));
     277            String lookupString = Font::normalizeSpaces(run.data(i), characterLookupRange);
    278278
    279279            Vector<SVGGlyphIdentifier> glyphs;
Note: See TracChangeset for help on using the changeset viewer.