Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(685)

Unified Diff: Source/core/html/HTMLTableRowsCollection.cpp

Issue 406843002: Optimize hasTagName when called on an HTMLElement / SVGElement (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/HTMLTableColElement.cpp ('k') | Source/core/html/HTMLTableSectionElement.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLTableRowsCollection.cpp
diff --git a/Source/core/html/HTMLTableRowsCollection.cpp b/Source/core/html/HTMLTableRowsCollection.cpp
index 610ad87296207db1bb6078ebfabaf007b3076e1d..e8f31e8a5fc7f895867a45941e8ce716d0a2f269 100644
--- a/Source/core/html/HTMLTableRowsCollection.cpp
+++ b/Source/core/html/HTMLTableRowsCollection.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008, 2011, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2008, 2011, 2012, 2014 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -38,19 +38,11 @@ namespace blink {
using namespace HTMLNames;
-static bool isInHead(Element* row)
+static inline bool isInSection(HTMLTableRowElement& row, const HTMLQualifiedName& sectionTag)
{
- return row->parentNode() && toElement(row->parentNode())->hasLocalName(theadTag);
-}
-
-static bool isInBody(Element* row)
-{
- return row->parentNode() && toElement(row->parentNode())->hasLocalName(tbodyTag);
-}
-
-static bool isInFoot(Element* row)
-{
- return row->parentNode() && toElement(row->parentNode())->hasLocalName(tfootTag);
+ // Because we know that the parent is a table or a section, it's safe to cast it to an HTMLElement
+ // giving us access to the faster hasTagName overload from that class.
+ return toHTMLElement(row.parentNode())->hasTagName(sectionTag);
}
HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement& table, HTMLTableRowElement* previous)
@@ -66,38 +58,38 @@ HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement& table,
HTMLElement* child = 0;
if (!previous)
child = Traversal<HTMLElement>::firstChild(table);
- else if (isInHead(previous))
+ else if (isInSection(*previous, theadTag))
child = Traversal<HTMLElement>::nextSibling(*previous->parentNode());
for (; child; child = Traversal<HTMLElement>::nextSibling(*child)) {
- if (child->hasLocalName(theadTag)) {
+ if (child->hasTagName(theadTag)) {
if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::firstChild(*child))
return row;
}
}
// If still looking at top level and bodies, find the next row in top level or the first in the next body section.
- if (!previous || isInHead(previous))
+ if (!previous || isInSection(*previous, theadTag))
child = Traversal<HTMLElement>::firstChild(table);
else if (previous->parentNode() == table)
child = Traversal<HTMLElement>::nextSibling(*previous);
- else if (isInBody(previous))
+ else if (isInSection(*previous, tbodyTag))
child = Traversal<HTMLElement>::nextSibling(*previous->parentNode());
for (; child; child = Traversal<HTMLElement>::nextSibling(*child)) {
if (isHTMLTableRowElement(child))
return toHTMLTableRowElement(child);
- if (child->hasLocalName(tbodyTag)) {
+ if (child->hasTagName(tbodyTag)) {
if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::firstChild(*child))
return row;
}
}
// Find the first row in the next foot section.
- if (!previous || !isInFoot(previous))
+ if (!previous || !isInSection(*previous, tfootTag))
child = Traversal<HTMLElement>::firstChild(table);
else
child = Traversal<HTMLElement>::nextSibling(*previous->parentNode());
for (; child; child = Traversal<HTMLElement>::nextSibling(*child)) {
- if (child->hasLocalName(tfootTag)) {
+ if (child->hasTagName(tfootTag)) {
if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::firstChild(*child))
return row;
}
@@ -109,7 +101,7 @@ HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement& table,
HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement& table)
{
for (HTMLElement* child = Traversal<HTMLElement>::lastChild(table); child; child = Traversal<HTMLElement>::previousSibling(*child)) {
- if (child->hasLocalName(tfootTag)) {
+ if (child->hasTagName(tfootTag)) {
if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::lastChild(*child))
return lastRow;
}
@@ -118,14 +110,14 @@ HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement& table)
for (HTMLElement* child = Traversal<HTMLElement>::lastChild(table); child; child = Traversal<HTMLElement>::previousSibling(*child)) {
if (isHTMLTableRowElement(child))
return toHTMLTableRowElement(child);
- if (child->hasLocalName(tbodyTag)) {
+ if (child->hasTagName(tbodyTag)) {
if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::lastChild(*child))
return lastRow;
}
}
for (HTMLElement* child = Traversal<HTMLElement>::lastChild(table); child; child = Traversal<HTMLElement>::previousSibling(*child)) {
- if (child->hasLocalName(theadTag)) {
+ if (child->hasTagName(theadTag)) {
if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::lastChild(*child))
return lastRow;
}
« no previous file with comments | « Source/core/html/HTMLTableColElement.cpp ('k') | Source/core/html/HTMLTableSectionElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698