+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
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)