[webkit-dev] Optimizing DOMNode _nodeWith
Matt Gough
devlists at softchaos.com
Mon Apr 24 08:19:11 PDT 2006
I have some Obj-c code which steps through all of the nodes in the
DOM. For a medium sized DOM (e.g news.google.com - just over 4000
nodes) this code takes over one tenth of a second on an 867MHz G4. A
third of that time is down to the calls to hasLocalName inside of:
+(DOMNode *) _nodeWith:(Node* *)
e.g.
HTMLElement* htmlElt = static_cast<HTMLElement*>(impl);
if (htmlElt->hasLocalName(htmlTag))
wrapperClass = [DOMHTMLHtmlElement class];
else if (htmlElt->hasLocalName(headTag))
etc etc
Now there is already a comment there that says:
// FIXME: We could make the HTML classes hand back
their class names and then use that to make
// the appropriate Obj-C class from the string.
I am guessing that this would go something like this, but before I go
to the trouble of doing this for every class could someone make sure
I am pondering the right thing.
e.g For each element type:
String HTMLElement::objcClassName() const
{
return String("DOMHTMLElement");
}
String HTMLDivElement::objcClassName() const
{
return String("DOMHTMLDivElement");
}
etc..
and then replace the all those tests in _nodeWith with:
if (impl->isHTMLElement()) {
// FIXME: Reflect marquee once the API has been
determined.
HTMLElement* htmlElt = static_cast<HTMLElement*>(impl);
String className(htmlElt->objcClassName());
NSString* asNSString = ?? How do I convert a String to an NSString?
wrapperClass = NSClassFromString(asNSString);
}
Does this all make sense?
Matt Gough
More information about the webkit-dev
mailing list