Skip to content

Commit

Permalink
Bug 1443316 - part 1 - micro-optimize purging expired preflight cache…
Browse files Browse the repository at this point in the history
… entries; r=ckerschb

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.
  • Loading branch information
froydnj committed Mar 7, 2018
1 parent 487cd0f commit edb9ed5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions netwerk/protocol/http/nsCORSListenerProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,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;
}
}
}
Expand Down

0 comments on commit edb9ed5

Please sign in to comment.