Optimize Object::GetObject. A 40% improvement on some testcases
1.1 --- a/src/core/object.cc Tue Nov 03 12:50:18 2009 +0300
1.2 +++ b/src/core/object.cc Wed Nov 04 22:08:21 2009 +0100
1.3 @@ -113,6 +113,7 @@
1.4 {
1.5 NS_ASSERT (CheckLoose ());
1.6 const Object *currentObject = this;
1.7 + const Object *prevObject = 0;
1.8 TypeId objectTid = Object::GetTypeId ();
1.9 do {
1.10 NS_ASSERT (currentObject != 0);
1.11 @@ -123,8 +124,21 @@
1.12 }
1.13 if (cur == tid)
1.14 {
1.15 + if (prevObject != 0)
1.16 + {
1.17 + // This is an attempt to 'cache' the result of this lookup.
1.18 + // the idea is that if we perform a lookup for a TypdId on this object,
1.19 + // we are likely to perform the same lookup later so, we re-order
1.20 + // the circular linked-list of objects here by putting the object we
1.21 + // just found at the head of the list. This optimization is
1.22 + // _extremely_ effective in general.
1.23 + const_cast<Object*>(prevObject)->m_next = currentObject->m_next;
1.24 + const_cast<Object*>(currentObject)->m_next = m_next;
1.25 + const_cast<Object*>(this)->m_next = (Object*)currentObject;
1.26 + }
1.27 return const_cast<Object *> (currentObject);
1.28 }
1.29 + prevObject = currentObject;
1.30 currentObject = currentObject->m_next;
1.31 } while (currentObject != this);
1.32 return 0;