Bug 1597679 - part 3: Create methods to compare given string with values of TextControlState, nsTextControlFrame, HTMLInputElement and HTMLTextAreaElement r=smaug

For avoiding unnecessary copy of string buffer only for comparing setting
value and current value, especially with `nsAutoString`, this patch
creates `*Equals()` methods for every class.

And also this avoids to call `nsContentUtils::PlatformToDOMLineBreaks()` in
most paths.

Differential Revision: https://phabricator.services.mozilla.com/D54331
This commit is contained in:
Masayuki Nakano
2019-11-25 06:35:17 +00:00
parent 16fa2f8998
commit f93c719628
8 changed files with 125 additions and 40 deletions

View File

@@ -201,13 +201,8 @@ void HTMLTextAreaElement::GetType(nsAString& aType) {
}
void HTMLTextAreaElement::GetValue(nsAString& aValue) {
nsAutoString value;
GetValueInternal(value, true);
// Normalize CRLF and CR to LF
nsContentUtils::PlatformToDOMLineBreaks(value);
aValue = value;
GetValueInternal(aValue, true);
MOZ_ASSERT(aValue.FindChar(static_cast<char16_t>('\r')) == -1);
}
void HTMLTextAreaElement::GetValueInternal(nsAString& aValue,
@@ -216,6 +211,11 @@ void HTMLTextAreaElement::GetValueInternal(nsAString& aValue,
mState->GetValue(aValue, aIgnoreWrap);
}
bool HTMLTextAreaElement::ValueEquals(const nsAString& aValue) const {
MOZ_ASSERT(mState);
return mState->ValueEquals(aValue);
}
TextEditor* HTMLTextAreaElement::GetTextEditor() {
MOZ_ASSERT(mState);
return mState->GetTextEditor();