Fix text break interators.
authorhausmann@webkit.org <hausmann@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Nov 2007 09:02:36 +0000 (09:02 +0000)
committerhausmann@webkit.org <hausmann@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Nov 2007 09:02:36 +0000 (09:02 +0000)
The break iterators where trying to be smart about the input
string and caching their results. Unfortunately a pointer/string length
comparison is not good enough in all cases (since some input is stack based
temp strings). Removed the caching but at the same time started to use a more
efficient constructor of QTextBoundaryFinder that doesn't need to malloc for
most strings.

Fixes two test cases that test "text-transform: capitalize".

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@27917 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/platform/qt/css1/text_properties/text-transCapitalize-expected.txt
LayoutTests/platform/qt/fast/css/textCapitalizeEdgeCases-expected.txt
WebCore/ChangeLog
WebCore/platform/qt/TextBreakIteratorQt.cpp

index 78c8c664a1a9173a5df77e0ebbf46134c29dc532..a9990a0cb8c54d34fe4224250b91ccc0b6e34e4b 100644 (file)
@@ -1,3 +1,21 @@
+2007-11-20  Lars Knoll  <lars@trolltech.com>
+
+        Reviewed by Simon.
+
+        Fix text break interators.
+        
+        The break iterators where trying to be smart about the input
+        string and caching their results. Unfortunately a pointer/string length
+        comparison is not good enough in all cases (since some input is stack based
+        temp strings). Removed the caching but at the same time started to use a more
+        efficient constructor of QTextBoundaryFinder that doesn't need to malloc for
+        most strings.
+        
+        Fixes two test cases that test "text-transform: capitalize".
+
+        * platform/qt/css1/text_properties/text-transCapitalize-expected.txt:
+        * platform/qt/fast/css/textCapitalizeEdgeCases-expected.txt:
+
 2007-11-19  Antti Koivisto  <antti@apple.com>
 
         Rubber-stamped by bdash.
index 52f2ca1033096f4674a7c3bb980465e2cbdfa8ad..ab16e8376a8e92c897739cffce4e72f57fb8eb0c 100644 (file)
@@ -425,11 +425,11 @@ layer at (0,0) size 800x1260
               RenderInline {SPAN} at (0,0) size 49x19
                 RenderText {#text} at (152,40) size 49x19
                   text run at (152,40) width 49: "Cheese"
-              RenderInline {SPAN} at (0,0) size 43x19
-                RenderText {#text} at (201,40) size 43x19
-                  text run at (201,40) width 43: "Burger"
-              RenderText {#text} at (244,40) size 118x19
-                text run at (244,40) width 118: " [House] ~Six -Big-"
+              RenderInline {SPAN} at (0,0) size 42x19
+                RenderText {#text} at (201,40) size 42x19
+                  text run at (201,40) width 42: "burger"
+              RenderText {#text} at (243,40) size 118x19
+                text run at (243,40) width 118: " [House] ~Six -Big-"
           RenderTableRow {TR} at (0,180) size 784x24
             RenderTableCell {TH} at (2,180) size 55x24 [bgcolor=#F8F8F8] [border: (1px solid #EEEEEE)] [r=4 c=0 rs=1 cs=1]
               RenderText {#text} at (19,2) size 16x20
index c9cc37737ad1a0c018d9c9666499812f2b8aa2ef..93f2938e072c90c3692da65f94777a33e7cb65d3 100644 (file)
@@ -24,11 +24,11 @@ layer at (0,0) size 800x600
             RenderInline {DIV} at (0,0) size 13x19
               RenderText {#text} at (26,11) size 13x19
                 text run at (26,11) width 13: "or"
-            RenderText {#text} at (39,11) size 42x19
-              text run at (39,11) width 42: "D With"
-            RenderImage {IMG} at (81,0) size 25x25
-            RenderText {#text} at (106,11) size 61x19
-              text run at (106,11) width 61: "An Image"
+            RenderText {#text} at (39,11) size 40x19
+              text run at (39,11) width 40: "d With"
+            RenderImage {IMG} at (79,0) size 25x25
+            RenderText {#text} at (104,11) size 61x19
+              text run at (104,11) width 61: "An Image"
           RenderBlock {DIV} at (0,30) size 694x0
           RenderBlock (anonymous) at (0,30) size 694x19
             RenderText {#text} at (0,0) size 33x19
index a778d84685a37dd2d4f207c281ee84748276d9d5..26b7f06f639c187d50cfbc21cc84bade57b9a278 100644 (file)
@@ -1,3 +1,24 @@
+2007-11-20  Lars Knoll  <lars@trolltech.com>
+
+        Reviewed by Simon.
+
+        Fix text break interators.
+        
+        The break iterators where trying to be smart about the input
+        string and caching their results. Unfortunately a pointer/string length
+        comparison is not good enough in all cases (since some input is stack based
+        temp strings). Removed the caching but at the same time started to use a more
+        efficient constructor of QTextBoundaryFinder that doesn't need to malloc for
+        most strings.
+        
+        Fixes two test cases that test "text-transform: capitalize".
+
+        * platform/qt/TextBreakIteratorQt.cpp:
+        (WebCore::wordBreakIterator):
+        (WebCore::characterBreakIterator):
+        (WebCore::lineBreakIterator):
+        (WebCore::sentenceBreakIterator):
+
 2007-11-20  Adam Treat  <treat@kde.org>
 
         * Build in release mode
index 63f20eab107d352ff4ab0ef81cf0d62816fca238..88b96808650ed290ea328208157d2f965089d39e 100644 (file)
@@ -26,6 +26,7 @@
 #include <QtCore/qtextboundaryfinder.h>
 #include <qdebug.h>
 
+// #define DEBUG_TEXT_ITERATORS
 #ifdef DEBUG_TEXT_ITERATORS
 #define DEBUG qDebug
 #else
@@ -37,93 +38,51 @@ namespace WebCore {
     class TextBreakIterator : public QTextBoundaryFinder
     {
     };
-
+    static QTextBoundaryFinder* iterator = 0;
+    static unsigned char buffer[1024];
 
     TextBreakIterator* wordBreakIterator(const UChar* string, int length)
     {
-        static QTextBoundaryFinder* iterator = 0;
-        static const UChar* cachedString = 0;
-        static int cachedLength = 0;
         if (!string)
             return 0;
-        if (string != cachedString || length != cachedLength) {
-            if (!iterator)
-                iterator = new QTextBoundaryFinder;
-
-            QString s((const QChar*)string, length);
-            DEBUG() << "wordBreakIterator" << length << s;
-            *iterator = QTextBoundaryFinder(QTextBoundaryFinder::Word, s);
-            cachedString = string;
-            cachedLength = length;
-        } else {
-            iterator->setPosition(0);
-        }
+        if (!iterator)
+            iterator = new QTextBoundaryFinder;
+
+        *iterator = QTextBoundaryFinder(QTextBoundaryFinder::Word, (const QChar *)string, length, buffer, sizeof(buffer));
         return static_cast<TextBreakIterator*>(iterator);
     }
 
     TextBreakIterator* characterBreakIterator(const UChar* string, int length)
     {
-        static QTextBoundaryFinder* iterator = 0;
-        static const UChar* cachedString = 0;
-        static int cachedLength = 0;
         if (!string)
             return 0;
-        if (string != cachedString || length != cachedLength) {
-            if (!iterator)
-                iterator = new QTextBoundaryFinder;
-
-            QString s((const QChar*)string, length);
-            DEBUG() << "characterBreakIterator" << length << s;
-            *iterator = QTextBoundaryFinder(QTextBoundaryFinder::Grapheme, s);
-            cachedString = string;
-            cachedLength = length;
-        } else {
-            iterator->setPosition(0);
-        }
+        if (!iterator)
+            iterator = new QTextBoundaryFinder;
+
+        *iterator = QTextBoundaryFinder(QTextBoundaryFinder::Grapheme, (const QChar *)string, length, buffer, sizeof(buffer));
         return static_cast<TextBreakIterator*>(iterator);
     }
 
     TextBreakIterator* lineBreakIterator(const UChar* string, int length)
     {
         static QTextBoundaryFinder *iterator = 0;
-        static const UChar *cachedString = 0;
-        static int cachedLength = 0;
         if (!string)
             return 0;
-        if (string != cachedString || length != cachedLength) {
-            if (!iterator)
-                iterator = new QTextBoundaryFinder;
-
-            QString s((const QChar *)string, length);
-            DEBUG() << "lineBreakIterator" << length << s;
-            *iterator = QTextBoundaryFinder(QTextBoundaryFinder::Line, s);
-            cachedString = string;
-            cachedLength = length;
-        } else {
-            iterator->setPosition(0);
-        }
+        if (!iterator)
+            iterator = new QTextBoundaryFinder;
+
+        *iterator = QTextBoundaryFinder(QTextBoundaryFinder::Line, (const QChar *)string, length, buffer, sizeof(buffer));
         return static_cast<TextBreakIterator*>(iterator);
     }
 
     TextBreakIterator* sentenceBreakIterator(const UChar* string, int length)
     {
-        static QTextBoundaryFinder* iterator = 0;
-        static const UChar* cachedString = 0;
-        static int cachedLength = 0;
         if (!string)
             return 0;
-        if (string != cachedString || length != cachedLength) {
-            if (!iterator)
-                iterator = new QTextBoundaryFinder;
-
-            QString s((const QChar*)string, length);
-            DEBUG() << "sentenceBreakIterator" << length << s;
-            *iterator = QTextBoundaryFinder(QTextBoundaryFinder::Sentence, s);
-            cachedString = string;
-            cachedLength = length;
-        } else {
-            iterator->setPosition(0);
-        }
+        if (!iterator)
+            iterator = new QTextBoundaryFinder;
+
+        *iterator = QTextBoundaryFinder(QTextBoundaryFinder::Sentence, (const QChar *)string, length, buffer, sizeof(buffer));
         return static_cast<TextBreakIterator*>(iterator);
     }