Suggested by Darin Adler. Reviewed by Dave Hyatt.
- speed up BidiIterator::direction()
* rendering/bidi.cpp:
(WebCore::BidiIterator::current): Made inline and corrected the
out-of-bounds condition to work with 0-length text and offsets beyond
the end of the text.
(WebCore::BidiIterator::direction): Changed to call current() and not
call the virtual method isListMarker() most of the time.
(WebCore::addMidpoint): Removed unnecessary null-check of smidpoints.
(WebCore::appendRunsForObject): Ditto.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@31011 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/rendering/bidi.cpp b/WebCore/rendering/bidi.cpp
index d4e3f8a..e5d2e37 100644
--- a/WebCore/rendering/bidi.cpp
+++ b/WebCore/rendering/bidi.cpp
@@ -298,30 +298,27 @@
return !obj;
}
-UChar BidiIterator::current() const
+inline UChar BidiIterator::current() const
{
if (!obj || !obj->isText())
return 0;
-
+
RenderText* text = static_cast<RenderText*>(obj);
- if (!text->characters())
+ if (pos >= text->textLength())
return 0;
-
+
return text->characters()[pos];
}
ALWAYS_INLINE Direction BidiIterator::direction() const
{
- if (!obj)
- return OtherNeutral;
- if (obj->isListMarker())
+ if (UChar c = current())
+ return Unicode::direction(c);
+
+ if (obj && obj->isListMarker())
return obj->style()->direction() == LTR ? LeftToRight : RightToLeft;
- if (!obj->isText())
- return OtherNeutral;
- RenderText* renderTxt = static_cast<RenderText*>(obj);
- if (pos >= renderTxt->textLength())
- return OtherNeutral;
- return Unicode::direction(renderTxt->characters()[pos]);
+
+ return OtherNeutral;
}
// -------------------------------------------------------------------------------------------------
@@ -376,9 +373,6 @@
static void addMidpoint(const BidiIterator& midpoint)
{
- if (!smidpoints)
- return;
-
if (smidpoints->size() <= sNumMidpoints)
smidpoints->grow(sNumMidpoints + 10);
@@ -392,7 +386,7 @@
(obj->isPositioned() && !obj->hasStaticX() && !obj->hasStaticY() && !obj->container()->isInlineFlow()))
return;
- bool haveNextMidpoint = (smidpoints && sCurrMidpoint < sNumMidpoints);
+ bool haveNextMidpoint = (sCurrMidpoint < sNumMidpoints);
BidiIterator nextMidpoint;
if (haveNextMidpoint)
nextMidpoint = smidpoints->at(sCurrMidpoint);
@@ -408,7 +402,7 @@
return appendRunsForObject(start, end, obj, bidi);
}
else {
- if (!smidpoints || !haveNextMidpoint || (obj != nextMidpoint.obj)) {
+ if (!haveNextMidpoint || (obj != nextMidpoint.obj)) {
bidi.addRun(new (obj->renderArena()) BidiRun(start, end, obj, bidi.context(), bidi.dir()));
return;
}