Discussion:
What is the faster way to determine if nsIDOMNSHTMLElement is an anchor
n179911
2010-05-22 13:46:05 UTC
Permalink
Hi,

Can you please tell me which is a faster way (run time performance) to
determine if nsIDOMNSHTMLElement is an anchor?

nsIDOMNSHTMLElement* element;
nsCOMPtr<nsIDOMNSHTMLAnchorElement> anchorElement =
do_QueryInterface(element);
if (anchorElement) {
// it is an anchor element....
}
or
nsIDOMNSHTMLElement element;
nsAutoString name;
childNode->GetNodeName(name);
if (name.LowerCaseEqualsLiteral("a")) {
// it is an anchor elemlent....
}

Or there is an even faster way?
Thank you.
Boris Zbarsky
2010-05-24 01:30:11 UTC
Permalink
Post by n179911
Can you please tell me which is a faster way (run time performance) to
determine if nsIDOMNSHTMLElement is an anchor?
Depends on how you define "anchor".
Post by n179911
nsIDOMNSHTMLElement* element;
nsCOMPtr<nsIDOMNSHTMLAnchorElement> anchorElement =
do_QueryInterface(element);
if (anchorElement) {
// it is an anchor element....
}
or
nsIDOMNSHTMLElement element;
nsAutoString name;
childNode->GetNodeName(name);
if (name.LowerCaseEqualsLiteral("a")) {
// it is an anchor elemlent....
Which of these is faster will likely depend on your compiler, 32-bit vs
64-bit, etc, etc. They're both fundamentally "slow", but any way that
only uses frozen APIs probably is.

You could make the second test a localName test to slightly speed it up,
I guess.

-Boris

Loading...