On Oct 21, 2008, at 3:11 AM, Julien Chaffraix wrote:

> Node* curNode = ... ;
>
> if (curNode->isElement() &&
> static_cast<Element*>(curNode)->hasTagName(HTMLNames::divTag)) {
>    // This is an html <div> element.
> }

There's no need to check isElement() here or cast to Element*. The  
hasTagName function is defined in the Node class, and always returns  
false for nodes that are not elements. So the best style code is  
something like this:

     if (curNode->hasTagName(HTMLNames::divTag)) {
         HTLMLDivElement* curDivElement =  
static_cast<HTMLDivElement*>(curNode);
         // do things with the element
     }

It's important that once you determine something is a specific element  
that you use the more specific pointer type, because you'll get more  
efficient algorithms for many functions if you use a more specific  
type, eliminating the need for the code to keep checking the type over  
and over again. So inside this if statement you would want to use  
curDivElement, not curNode.

     -- Darin

_______________________________________________
webkit-dev mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev

Reply via email to