Issue #2703 - Part 2: Don't repeatedly construct comparators when checking cache entries.

nsCaseInsensitiveCStringComparator ought to be cheap to construct, but
the object actually has a vtable to install and whatnot.  So it's
beneficial to pull the construction of it outside of the headers loop.
This commit is contained in:
Shadow 2025-03-14 13:47:55 +00:00 • committed by roytam1
commit 7854198085

View file

@ -250,9 +250,9 @@ nsPreflightCache::CacheEntry::CheckRequest(const nsCString& aMethod,
for (uint32_t i = 0; i < aHeaders.Length(); ++i) {
uint32_t j;
const auto& comparator = nsCaseInsensitiveCStringComparator();
for (j = 0; j < mHeaders.Length(); ++j) {
if (aHeaders[i].Equals(mHeaders[j].token,
nsCaseInsensitiveCStringComparator())) {
if (aHeaders[i].Equals(mHeaders[j].token, comparator)) {
break;
}
}
@ -1385,8 +1385,8 @@ nsCORSPreflightListener::CheckPreflightRequestApproved(nsIRequest* aRequest)
) {
continue;
}
if (!headers.Contains(mPreflightHeaders[i],
nsCaseInsensitiveCStringArrayComparator())) {
const auto& comparator = nsCaseInsensitiveCStringArrayComparator();
if (!headers.Contains(mPreflightHeaders[i], comparator)) {
LogBlockedRequest(aRequest, "CORSMissingAllowHeaderFromPreflight",
NS_ConvertUTF8toUTF16(mPreflightHeaders[i]).get());
return NS_ERROR_DOM_BAD_URI;