Backed out changeset 57d1339ad1c0 (bug 1380154)

This commit is contained in:
Sebastian Hengst 2017-08-07 21:42:09 +02:00
Родитель b91c660165
Коммит c0bf2b4e8d
2 изменённых файлов: 0 добавлений и 66 удалений

Просмотреть файл

@ -9,10 +9,8 @@
// http://wiki.mozilla.org/Gecko:Effective_TLD_Service
#include "mozilla/ArrayUtils.h"
#include "mozilla/HashFunctions.h"
#include "mozilla/MemoryReporting.h"
#include "MainThreadUtils.h"
#include "nsEffectiveTLDService.h"
#include "nsIIDNService.h"
#include "nsNetUtil.h"
@ -212,20 +210,6 @@ nsEffectiveTLDService::GetBaseDomainInternal(nsCString &aHostname,
if (result == PR_SUCCESS)
return NS_ERROR_HOST_IS_IP_ADDRESS;
// Lookup in the cache if this is a normal query.
TLDCacheEntry* entry = nullptr;
if (aAdditionalParts == 1) {
if (LookupForAdd(aHostname, &entry)) {
// There was a match, just return the cached value.
aBaseDomain = entry->mBaseDomain;
if (trailingDot) {
aBaseDomain.Append('.');
}
return NS_OK;
}
}
// Walk up the domain tree, most specific to least specific,
// looking for matches at each level. Note that a given level may
// have multiple attributes (e.g. IsWild() and IsNormal()).
@ -306,13 +290,6 @@ nsEffectiveTLDService::GetBaseDomainInternal(nsCString &aHostname,
return NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS;
aBaseDomain = Substring(iter, end);
// Update the MRU table if in use.
if (entry) {
entry->mHost = aHostname;
entry->mBaseDomain = aBaseDomain;
}
// add on the trailing dot, if applicable
if (trailingDot)
aBaseDomain.Append('.');
@ -335,13 +312,3 @@ nsEffectiveTLDService::NormalizeHostname(nsCString &aHostname)
ToLowerCase(aHostname);
return NS_OK;
}
bool
nsEffectiveTLDService::LookupForAdd(const nsACString& aHost, TLDCacheEntry** aEntry)
{
MOZ_ASSERT(NS_IsMainThread());
const uint32_t hash = HashString(aHost.BeginReading(), aHost.Length());
*aEntry = &mMruTable[hash % kTableSize];
return (*aEntry)->mHost == aHost;
}

Просмотреть файл

@ -37,40 +37,7 @@ private:
~nsEffectiveTLDService();
nsCOMPtr<nsIIDNService> mIDNService;
// The DAFSA provides a compact encoding of the rather large eTLD list.
mozilla::Dafsa mGraph;
struct TLDCacheEntry
{
nsCString mHost;
nsCString mBaseDomain;
};
// We use a small most recently used cache to compensate for DAFSA lookups
// being slightly slower than a binary search on a larger table of strings.
//
// We first check the cache for a matching result and avoid a DAFSA lookup
// if a match is found. Otherwise we lookup the domain in the DAFSA and then
// cache the result. During standard browsing the same domains are repeatedly
// fed into |GetBaseDomainInternal| so this ends up being an effective
// mitigation getting about a 99% hit rate with four tabs open.
//
// A size of 31 is used rather than a more logical power-of-two such as 32
// since it is a prime number and provides fewer collisions when when used
// with our hash algorithms.
static const uint32_t kTableSize = 31;
TLDCacheEntry mMruTable[kTableSize];
/**
* Performs a lookup on the MRU table and provides a pointer to the hash
* entry that matched or should be used for adding this host.
*
* @param aHost The host to lookup.
* @param aEntry Out param, the entry in the MRU table to use.
* @return True if a match was found, false if there was a miss.
*/
inline bool LookupForAdd(const nsACString& aHost, TLDCacheEntry** aEntry);
};
#endif // EffectiveTLDService_h