Bug 1368888 - Don't get previous value twice in input.value setter. r=smaug

We get previous input.value twice in HTMLInputElement::SetValue and nsTextEditorState::SetValue when setting input.value.  Since nsTextEditorState::GetValue uses DocumentEncoder, it is expensive.  So we should use old value as parameter of nsTextEditorState::SetValue if possible.

MozReview-Commit-ID: A1UPfETTVCn
This commit is contained in:
Makoto Kato
2017-06-14 18:21:01 +09:00
parent b0a8a91658
commit 6850a4f808
4 changed files with 53 additions and 7 deletions

View File

@@ -1873,8 +1873,12 @@ HTMLInputElement::SetValue(const nsAString& aValue, CallerType aCallerType,
nsAutoString currentValue;
GetValue(currentValue, aCallerType);
// Some types sanitize value, so GetValue doesn't return pure
// previous value correctly.
nsresult rv =
SetValueInternal(aValue,
(IsExperimentalMobileType(mType) || IsDateTimeInputType(mType)) ?
nullptr : &currentValue,
nsTextEditorState::eSetValue_ByContent |
nsTextEditorState::eSetValue_Notify |
nsTextEditorState::eSetValue_MoveCursorToEndIfValueChanged);
@@ -3032,7 +3036,9 @@ HTMLInputElement::UpdateFileList()
}
nsresult
HTMLInputElement::SetValueInternal(const nsAString& aValue, uint32_t aFlags)
HTMLInputElement::SetValueInternal(const nsAString& aValue,
const nsAString* aOldValue,
uint32_t aFlags)
{
NS_PRECONDITION(GetValueMode() != VALUE_MODE_FILENAME,
"Don't call SetValueInternal for file inputs");
@@ -3056,7 +3062,7 @@ HTMLInputElement::SetValueInternal(const nsAString& aValue, uint32_t aFlags)
}
if (IsSingleLineTextControl(false)) {
if (!mInputData.mState->SetValue(value, aFlags)) {
if (!mInputData.mState->SetValue(value, aOldValue, aFlags)) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (mType == NS_FORM_INPUT_EMAIL) {