Commit e967f240 authored by eric@webkit.org's avatar eric@webkit.org

2009-09-26 Shu Chang <Chang.Shu@nokia.com>

        Reviewed by Alexey Proskuryakov.

        Optimize the code so only the text from start to end is scanned.
        https://bugs.webkit.org/show_bug.cgi?id=29092

        On a platform with webkit+Qt+Symbian, the parsing time for a 600K text
        file improved from 400ms to 40ms (10x faster).

        * dom/Text.cpp:
        (WebCore::Text::createWithLengthLimit):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@48790 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 087ef480
2009-09-26 Shu Chang <Chang.Shu@nokia.com>
Reviewed by Alexey Proskuryakov.
Optimize the code so only the text from start to end is scanned.
https://bugs.webkit.org/show_bug.cgi?id=29092
On a platform with webkit+Qt+Symbian, the parsing time for a 600K text
file improved from 400ms to 40ms (10x faster).
* dom/Text.cpp:
(WebCore::Text::createWithLengthLimit):
2009-09-26 Xiaomei Ji <xji@chromium.org>
Reviewed by Eric Seidel.
......
......@@ -315,10 +315,15 @@ PassRefPtr<Text> Text::createWithLengthLimit(Document* document, const String& d
unsigned end = start + min(charsLeft, maxChars);
// Check we are not on an unbreakable boundary.
TextBreakIterator* it = characterBreakIterator(data.characters(), dataLength);
if (end < dataLength && !isTextBreak(it, end))
end = textBreakPreceding(it, end);
// Some text break iterator implementations work best if the passed buffer is as small as possible,
// see <https://bugs.webkit.org/show_bug.cgi?id=29092>.
// We need at least two characters look-ahead to account for UTF-16 surrogates.
if (end < dataLength) {
TextBreakIterator* it = characterBreakIterator(data.characters() + start, (end + 2 > dataLength) ? dataLength - start : end - start + 2);
if (!isTextBreak(it, end - start))
end = textBreakPreceding(it, end - start) + start;
}
// If we have maxChars of unbreakable characters the above could lead to
// an infinite loop.
// FIXME: It would be better to just have the old value of end before calling
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment