diff options
author | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-09 00:27:51 +0000 |
---|---|---|
committer | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-09 00:27:51 +0000 |
commit | 42d236bf62e2ee51b3640ac28d8d6565ce92f9ac (patch) | |
tree | 0b16aa98b5e43f5e34fe72cfed39522bba3860c9 /chrome/renderer | |
parent | 2bfc319546d3cd8d2611f22a5cf58e1996ea8ec9 (diff) | |
download | chromium_src-42d236bf62e2ee51b3640ac28d8d6565ce92f9ac.zip chromium_src-42d236bf62e2ee51b3640ac28d8d6565ce92f9ac.tar.gz chromium_src-42d236bf62e2ee51b3640ac28d8d6565ce92f9ac.tar.bz2 |
AutoFill optimization for form label finding.
This replaces calls to |innnerText()| with calls to |nodeValue()| for performance
gains.
BUG=40306
TEST=FormManagerTest.Label
Review URL: http://codereview.chromium.org/1622013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44034 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/form_manager.cc | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/chrome/renderer/form_manager.cc b/chrome/renderer/form_manager.cc index 98c5513..d688e6e 100644 --- a/chrome/renderer/form_manager.cc +++ b/chrome/renderer/form_manager.cc @@ -45,6 +45,19 @@ namespace { // it's not necessary. const size_t kRequiredAutoFillFields = 3; +// Returns the node value of the first child of |element| if the first child +// is text. This is faster alternative to |innerText()| for performance +// critical operations when the child structure of element is known. +string16 GetChildText(const WebElement& element) { + string16 element_text; + WebNode child = element.firstChild(); + if (!child.isNull() && child.isTextNode()) { + element_text = child.nodeValue(); + TrimWhitespace(element_text, TRIM_ALL, &element_text); + } + return element_text; +} + } // namespace FormManager::FormManager() { @@ -152,7 +165,7 @@ bool FormManager::WebFormElementToFormData(const WebFormElement& element, // element, get the corresponding form control element, use the form control // element's name as a key into the <name, FormField> map to find the // previously created FormField and set the FormField's label to the - // innerText() of the label element. + // label.firstChild().nodeValue() of the label element. WebNodeList labels = element.getElementsByTagName("label"); for (unsigned i = 0; i < labels.length(); ++i) { WebLabelElement label = labels.item(i).toElement<WebLabelElement>(); @@ -164,7 +177,7 @@ bool FormManager::WebFormElementToFormData(const WebFormElement& element, std::map<string16, FormField*>::iterator iter = name_map.find(field_element.nameForAutofill()); if (iter != name_map.end()) - iter->second->set_label(label.innerText()); + iter->second->set_label(GetChildText(label)); } // Copy the created FormFields into the resulting FormData object. @@ -434,7 +447,7 @@ string16 FormManager::LabelForElement(const WebFormControlElement& element) { if (e.hasTagName("label")) { WebLabelElement label = e.toElement<WebLabelElement>(); if (label.correspondingControl() == element) - return label.innerText(); + return GetChildText(label); } } |