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

Unified Diff: third_party/WebKit/Source/core/html/HTMLSelectElement.cpp

Issue 2126023005: SELECT element: Improve performance of HTMLSelectElement::optionIndexToBeShown(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
Index: third_party/WebKit/Source/core/html/HTMLSelectElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLSelectElement.cpp b/third_party/WebKit/Source/core/html/HTMLSelectElement.cpp
index 7a39cb97914cea24ecf4338e73a50bb5a5421483..84fbc2cad5e71bef1ff6b4eabc42b2b7b05f7066 100644
--- a/third_party/WebKit/Source/core/html/HTMLSelectElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLSelectElement.cpp
@@ -1122,8 +1122,8 @@ void HTMLSelectElement::selectOption(HTMLOptionElement* element, int optionIndex
// Need to check usesMenuList() again because event handlers might
// change the status.
if (usesMenuList()) {
- // didSetSelectedIndex() is O(N) because of optionToListIndex.
- toLayoutMenuList(layoutObject)->didSetSelectedIndex(optionIndex);
+ // didSelectOption() is O(N) because of HTMLOptionElement::index().
+ toLayoutMenuList(layoutObject)->didSelectOption(element);
}
}
}
@@ -1985,17 +1985,14 @@ void HTMLSelectElement::setIndexToSelectOnCancel(int listIndex)
layoutObject()->updateFromElement();
}
-int HTMLSelectElement::optionIndexToBeShown() const
+HTMLOptionElement* HTMLSelectElement::optionToBeShown() const
{
- if (m_indexToSelectOnCancel >= 0)
- return listToOptionIndex(m_indexToSelectOnCancel);
- // TODO(tkent): HTMLOptionElement::index() is O(N). This function should
- // return HTMLOptionElement*.
+ if (m_indexToSelectOnCancel >= 0 && static_cast<size_t>(m_indexToSelectOnCancel) < listItems().size() && isHTMLOptionElement(listItems()[m_indexToSelectOnCancel]))
+ return toHTMLOptionElement(listItems()[m_indexToSelectOnCancel]);
if (m_suggestedOption)
- return m_suggestedOption->index();
- int optionIndex = m_lastOnChangeOption ? m_lastOnChangeOption->index() : -1;
- DCHECK_EQ(optionIndex, selectedIndex());
- return optionIndex;
+ return m_suggestedOption;
+ DCHECK_EQ(selectedOption(), m_lastOnChangeOption);
+ return m_lastOnChangeOption;
}
void HTMLSelectElement::valueChanged(unsigned listIndex)
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSelectElement.h ('k') | third_party/WebKit/Source/core/layout/LayoutMenuList.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698