+2005-12-02 Timothy Hatcher <timothy@apple.com>
+
+ Reviewed by Maciej.
+
+ Cache the lastItem and lastItemOffset for fast retrieval of the
+ same index or indeicies greater than lastItemOffset. Also cache
+ the length. Like other node lists these cached values rest when the
+ subtree under the root node changes.
+
+ * khtml/xml/dom_nodeimpl.cpp:
+ (ChildNodeListImpl::length): Use cachedLength when possible.
+ (ChildNodeListImpl::item): Use lastItemOffset and lastItem if we can.
+
2005-12-01 Graham Dennis <Graham.Dennis@gmail.com>
<http://bugzilla.opendarwin.org/show_bug.cgi?id=4003>
if (!remainingOffset) {
lastItem = n;
lastItemOffset = offset;
- isItemCacheValid = 1;
+ isItemCacheValid = true;
return n;
}
remainingOffset--;
{
isLengthCacheValid = false;
isItemCacheValid = false;
+ lastItem = 0;
}
ChildNodeListImpl::ChildNodeListImpl( NodeImpl *n )
unsigned ChildNodeListImpl::length() const
{
+ if (isLengthCacheValid)
+ return cachedLength;
+
unsigned len = 0;
NodeImpl *n;
for(n = rootNode->firstChild(); n != 0; n = n->nextSibling())
len++;
+ cachedLength = len;
+ isLengthCacheValid = true;
+
return len;
}
unsigned int pos = 0;
NodeImpl *n = rootNode->firstChild();
- while( n != 0 && pos < index )
- {
+ if (isItemCacheValid) {
+ if (index == lastItemOffset) {
+ return lastItem;
+ } else if (index > lastItemOffset) {
+ n = lastItem;
+ pos = lastItemOffset;
+ }
+ }
+
+ while (n && pos < index) {
n = n->nextSibling();
pos++;
}
- return n;
+ if (n) {
+ lastItem = n;
+ lastItemOffset = pos;
+ isItemCacheValid = true;
+ return n;
+ }
+
+ return 0;
}
bool ChildNodeListImpl::nodeMatches(NodeImpl *testNode) const