Re: What is the faster way to determine if nsIDOMNSHTMLElement is an anchor
Boris Zbarsky <[email protected]> Sun, 23 May 2010 21:30:11 -0400
| Newsgroups | gmane.comp.mozilla.devel.dom |
|---|---|
| Message-ID | <[email protected]> |
On 5/22/10 9:46 AM, n179911 wrote:
> 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".
> 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