Reviewed by Richard.
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Mar 2005 23:08:46 +0000 (23:08 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Mar 2005 23:08:46 +0000 (23:08 +0000)
        - fixed <rdar://problem/4037700> Every character typed causes stat call for /usr/share/icu/icudt32b_char.brk

        * khtml/rendering/render_text.cpp:
        (getCharacterBreakIterator): Added. Helper that sets up an iterator for the passed-in text.
        Shares a single global iterator (fast, albeit not thread-safe).
        (RenderText::previousOffset): Changed to call getCharacterBreakIterator.
        (RenderText::nextOffset): Ditto.

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

WebCore/ChangeLog-2005-08-23
WebCore/khtml/rendering/render_text.cpp

index 8712d22632a21146d2153c6db53caf036ffe491d..e204f78b68935ce228093337b67b12d768192b84 100644 (file)
@@ -1,3 +1,15 @@
+2005-03-05  Darin Adler  <darin@apple.com>
+
+        Reviewed by Richard.
+
+        - fixed <rdar://problem/4037700> Every character typed causes stat call for /usr/share/icu/icudt32b_char.brk
+
+        * khtml/rendering/render_text.cpp:
+        (getCharacterBreakIterator): Added. Helper that sets up an iterator for the passed-in text.
+        Shares a single global iterator (fast, albeit not thread-safe).
+        (RenderText::previousOffset): Changed to call getCharacterBreakIterator.
+        (RenderText::nextOffset): Ditto.
+
 2005-03-05  Ken Kocienda  <kocienda@apple.com>
 
         Reviewed by Darin
index 4154c962ade0375b727bf1c677d37d645744c206..80c248b9cac73560899af3db75f50fda56525b96 100644 (file)
@@ -688,49 +688,54 @@ unsigned long InlineTextBox::caretMaxRenderedOffset() const
     return m_start + m_len;
 }
 
-long RenderText::previousOffset (long current) const
+#if HAVE_ICU_LIBRARY
+
+static UBreakIterator *getCharacterBreakIterator(const DOMStringImpl *i)
 {
-#if !HAVE_ICU_LIBRARY
-    long previousOffset = current - 1;
-    return previousOffset;
-#else
-    UErrorCode status = U_ZERO_ERROR;
-    
     // The locale is currently ignored when determining character cluster breaks.  This may change
     // in the future (according to Deborah Goldsmith).
-    UBreakIterator* iterator = ubrk_open (UBRK_CHARACTER, "en_us", (const UChar*)str->s, str->l, &status);
+    static bool createdIterator = false;
+    static UBreakIterator *iterator;
+    UErrorCode status;
+    if (!createdIterator) {
+        status = U_ZERO_ERROR;
+        iterator = ubrk_open(UBRK_CHARACTER, "en_us", NULL, 0, &status);
+    }
+    if (!iterator) {
+        return NULL;
+    }
+    status = U_ZERO_ERROR;
+    ubrk_setText(iterator, reinterpret_cast<const UChar *>(i->s), i->l, &status);
+    if (status != U_ZERO_ERROR) {
+        return NULL;
+    }
+    return iterator;
+}
+
+#endif
+
+long RenderText::previousOffset (long current) const
+{
+#if HAVE_ICU_LIBRARY
+    UBreakIterator *iterator = getCharacterBreakIterator(str);
     if (iterator) {
-        long off1 = ubrk_preceding (iterator, current);        
-        ubrk_close (iterator);
-        return off1;
+        return ubrk_preceding(iterator, current);
     }
-    
-    return current - 1;
 #endif
+    return current - 1;
 }
 
 long RenderText::nextOffset (long current) const
 {
-#if !HAVE_ICU_LIBRARY
-    long nextOffset = current + 1;
-    return nextOffset;
-#else
-    UErrorCode status = U_ZERO_ERROR;
-
-    // The locale is currently ignored when determining character cluster breaks.  This may change
-    // in the future (according to Deborah Goldsmith).
-    UBreakIterator* iterator = ubrk_open (UBRK_CHARACTER, "en_us", (const UChar*)str->s, str->l, &status);
+#if HAVE_ICU_LIBRARY
+    UBreakIterator *iterator = getCharacterBreakIterator(str);
     if (iterator) {
-        long off1 = ubrk_following (iterator, current);
-        ubrk_close (iterator);
-        return off1;
+        return ubrk_following(iterator, current);
     }
-    
-    return current + 1;
 #endif
+    return current + 1;
 }
 
-
 #define LOCAL_WIDTH_BUF_SIZE   1024
 
 int InlineTextBox::offsetForPosition(int _x, bool includePartialGlyphs)