From d678f508de4296df4fb29ffb892e158003d849d4 Mon Sep 17 00:00:00 2001 From: Shadow Date: Fri, 14 Mar 2025 13:39:08 +0000 Subject: [PATCH] Issue #2703 - Part 1: micro-optimize purging expired preflight cache entries. The entries in mMethods and mHeaders aren't sorted in any special way, so we can remove expired entries using UnorderedRemoveElementAt, which is faster than RemoveElementAt. --- netwerk/protocol/http/nsCORSListenerProxy.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/netwerk/protocol/http/nsCORSListenerProxy.cpp b/netwerk/protocol/http/nsCORSListenerProxy.cpp index add904092a..a5f5fab43b 100644 --- a/netwerk/protocol/http/nsCORSListenerProxy.cpp +++ b/netwerk/protocol/http/nsCORSListenerProxy.cpp @@ -215,15 +215,18 @@ static bool EnsurePreflightCache() void nsPreflightCache::CacheEntry::PurgeExpired(TimeStamp now) { - uint32_t i; - for (i = 0; i < mMethods.Length(); ++i) { + for (uint32_t i = 0, len = mMethods.Length(); i < len; ++i) { if (now >= mMethods[i].expirationTime) { - mMethods.RemoveElementAt(i--); + mMethods.UnorderedRemoveElementAt(i); + --i; // Examine the element again, if necessary. + --len; } } - for (i = 0; i < mHeaders.Length(); ++i) { + for (uint32_t i = 0, len = mHeaders.Length(); i < len; ++i) { if (now >= mHeaders[i].expirationTime) { - mHeaders.RemoveElementAt(i--); + mHeaders.UnorderedRemoveElementAt(i); + --i; // Examine the element again, if necessary. + --len; } } }