Bug 1641245 - Make string comparators not virtual. r=froydnj,necko-reviewers,geckoview-reviewers,jgilbert,agi,valentin
There's no use case for stateful comparators, so they can be just plain function pointers. This is used in some hot places like CSS selector matching. Differential Revision: https://phabricator.services.mozilla.com/D77084
This commit is contained in:
@@ -457,7 +457,7 @@ nsAutoCompleteController::HandleKeyNavigation(uint32_t aKey, bool* _retval) {
|
||||
// autofilled. Else, fill the result and move the caret to the end.
|
||||
int32_t start;
|
||||
if (value.Equals(mPlaceholderCompletionString,
|
||||
nsCaseInsensitiveStringComparator())) {
|
||||
nsCaseInsensitiveStringComparator)) {
|
||||
start = mSearchString.Length();
|
||||
value = mPlaceholderCompletionString;
|
||||
SetValueOfInputTo(
|
||||
@@ -517,7 +517,7 @@ nsAutoCompleteController::HandleKeyNavigation(uint32_t aKey, bool* _retval) {
|
||||
oldResult != nsIAutoCompleteResult::RESULT_FAILURE &&
|
||||
NS_SUCCEEDED(mResults[0]->GetSearchString(oldSearchString)) &&
|
||||
oldSearchString.Equals(mSearchString,
|
||||
nsCaseInsensitiveStringComparator())) {
|
||||
nsCaseInsensitiveStringComparator)) {
|
||||
if (mMatchCount) {
|
||||
OpenPopup();
|
||||
}
|
||||
@@ -612,8 +612,7 @@ nsAutoCompleteController::HandleKeyNavigation(uint32_t aKey, bool* _retval) {
|
||||
suggestedValue = inputValue;
|
||||
}
|
||||
|
||||
if (value.Equals(suggestedValue,
|
||||
nsCaseInsensitiveStringComparator())) {
|
||||
if (value.Equals(suggestedValue, nsCaseInsensitiveStringComparator)) {
|
||||
SetValueOfInputTo(
|
||||
value, nsIAutoCompleteInput::TEXTVALUE_REASON_COMPLETEDEFAULT);
|
||||
input->SelectTextRange(value.Length(), value.Length());
|
||||
@@ -1046,7 +1045,7 @@ void nsAutoCompleteController::MaybeCompletePlaceholder() {
|
||||
selectionEnd == selectionStart &&
|
||||
selectionEnd == (int32_t)mSearchString.Length() &&
|
||||
StringBeginsWith(mPlaceholderCompletionString, mSearchString,
|
||||
nsCaseInsensitiveStringComparator());
|
||||
nsCaseInsensitiveStringComparator);
|
||||
|
||||
if (usePlaceholderCompletion) {
|
||||
CompleteValue(mPlaceholderCompletionString);
|
||||
@@ -1185,7 +1184,7 @@ nsresult nsAutoCompleteController::EnterMatch(bool aIsPopupSelection,
|
||||
GetResultValueAt(selectedIndex, true, value);
|
||||
} else if (mDefaultIndexCompleted &&
|
||||
inputValue.Equals(mPlaceholderCompletionString,
|
||||
nsCaseInsensitiveStringComparator())) {
|
||||
nsCaseInsensitiveStringComparator)) {
|
||||
// We also need to fill-in the value if the default index completion was
|
||||
// confirmed, though we cannot use the selectedIndex cause the selection
|
||||
// may have been changed by the mouse in the meanwhile.
|
||||
@@ -1241,7 +1240,7 @@ nsresult nsAutoCompleteController::EnterMatch(bool aIsPopupSelection,
|
||||
nsAutoString matchValue;
|
||||
result->GetValueAt(j, matchValue);
|
||||
if (suggestedValue.Equals(matchValue,
|
||||
nsCaseInsensitiveStringComparator())) {
|
||||
nsCaseInsensitiveStringComparator)) {
|
||||
nsAutoString finalMatchValue;
|
||||
result->GetFinalCompleteValueAt(j, finalMatchValue);
|
||||
value = finalMatchValue;
|
||||
@@ -1474,7 +1473,7 @@ nsresult nsAutoCompleteController::CompleteDefaultIndex(int32_t aResultIndex) {
|
||||
selectionEnd == (int32_t)mPlaceholderCompletionString.Length() &&
|
||||
selectionStart == (int32_t)mSearchString.Length() &&
|
||||
StringBeginsWith(mPlaceholderCompletionString, mSearchString,
|
||||
nsCaseInsensitiveStringComparator());
|
||||
nsCaseInsensitiveStringComparator);
|
||||
|
||||
// Don't try to automatically complete to the first result if there's already
|
||||
// a selection or the cursor isn't at the end of the input. In case the
|
||||
@@ -1567,9 +1566,8 @@ nsresult nsAutoCompleteController::GetDefaultCompleteValue(int32_t aResultIndex,
|
||||
|
||||
nsAutoString resultValue;
|
||||
result->GetValueAt(defaultIndex, resultValue);
|
||||
if (aPreserveCasing &&
|
||||
StringBeginsWith(resultValue, mSearchString,
|
||||
nsCaseInsensitiveStringComparator())) {
|
||||
if (aPreserveCasing && StringBeginsWith(resultValue, mSearchString,
|
||||
nsCaseInsensitiveStringComparator)) {
|
||||
// We try to preserve user casing, otherwise we would end up changing
|
||||
// the case of what he typed, if we have a result with a different casing.
|
||||
// For example if we have result "Test", and user starts writing "tuna",
|
||||
@@ -1601,7 +1599,7 @@ nsresult nsAutoCompleteController::GetFinalDefaultCompleteValue(
|
||||
result->GetValueAt(defaultIndex, _retval);
|
||||
nsAutoString inputValue;
|
||||
input->GetTextValue(inputValue);
|
||||
if (!_retval.Equals(inputValue, nsCaseInsensitiveStringComparator())) {
|
||||
if (!_retval.Equals(inputValue, nsCaseInsensitiveStringComparator)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@@ -1625,9 +1623,8 @@ nsresult nsAutoCompleteController::CompleteValue(nsString& aValue)
|
||||
const int32_t mSearchStringLength = mSearchString.Length();
|
||||
int32_t endSelect = aValue.Length(); // By default, select all of aValue.
|
||||
|
||||
if (aValue.IsEmpty() ||
|
||||
StringBeginsWith(aValue, mSearchString,
|
||||
nsCaseInsensitiveStringComparator())) {
|
||||
if (aValue.IsEmpty() || StringBeginsWith(aValue, mSearchString,
|
||||
nsCaseInsensitiveStringComparator)) {
|
||||
// aValue is empty (we were asked to clear mInput), or mSearchString
|
||||
// matches the beginning of aValue. In either case we can simply
|
||||
// autocomplete to aValue.
|
||||
@@ -1650,7 +1647,7 @@ nsresult nsAutoCompleteController::CompleteValue(nsString& aValue)
|
||||
if ((endSelect < findIndex + mSearchStringLength) ||
|
||||
!scheme.EqualsLiteral("http") ||
|
||||
!Substring(aValue, findIndex, mSearchStringLength)
|
||||
.Equals(mSearchString, nsCaseInsensitiveStringComparator())) {
|
||||
.Equals(mSearchString, nsCaseInsensitiveStringComparator)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user