зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1247850 - Shrink NameTableKey in nsStaticCaseInsensitiveNameTable. r=froydnj,erahm.
This patch removes NameTableEntry::mString. This requires adding mNameArray to NameTableKey so that we can index off it in matchNameKeysCaseInsensitive(). This change saves 41.5 KiB per process.
This commit is contained in:
Родитель
6f8f413e72
Коммит
9eda713f8b
|
@ -19,48 +19,47 @@ using namespace mozilla;
|
|||
|
||||
struct NameTableKey
|
||||
{
|
||||
explicit NameTableKey(const nsAFlatCString* aKeyStr)
|
||||
: mIsUnichar(false)
|
||||
NameTableKey(const nsDependentCString aNameArray[],
|
||||
const nsAFlatCString* aKeyStr)
|
||||
: mNameArray(aNameArray)
|
||||
, mIsUnichar(false)
|
||||
{
|
||||
mKeyStr.m1b = aKeyStr;
|
||||
}
|
||||
|
||||
explicit NameTableKey(const nsAFlatString* aKeyStr)
|
||||
: mIsUnichar(true)
|
||||
NameTableKey(const nsDependentCString aNameArray[],
|
||||
const nsAFlatString* aKeyStr)
|
||||
: mNameArray(aNameArray)
|
||||
, mIsUnichar(true)
|
||||
{
|
||||
mKeyStr.m2b = aKeyStr;
|
||||
}
|
||||
|
||||
bool mIsUnichar;
|
||||
const nsDependentCString* mNameArray;
|
||||
union
|
||||
{
|
||||
const nsAFlatCString* m1b;
|
||||
const nsAFlatString* m2b;
|
||||
} mKeyStr;
|
||||
bool mIsUnichar;
|
||||
};
|
||||
|
||||
struct NameTableEntry : public PLDHashEntryHdr
|
||||
{
|
||||
// no ownership here!
|
||||
const nsAFlatCString* mString;
|
||||
int32_t mIndex;
|
||||
};
|
||||
|
||||
static bool
|
||||
matchNameKeysCaseInsensitive(PLDHashTable*, const PLDHashEntryHdr* aHdr,
|
||||
const void* aKey)
|
||||
const void* aVoidKey)
|
||||
{
|
||||
const NameTableEntry* entry = static_cast<const NameTableEntry*>(aHdr);
|
||||
const NameTableKey* keyValue = static_cast<const NameTableKey*>(aKey);
|
||||
const nsAFlatCString* entryKey = entry->mString;
|
||||
auto entry = static_cast<const NameTableEntry*>(aHdr);
|
||||
auto key = static_cast<const NameTableKey*>(aVoidKey);
|
||||
const nsDependentCString* name = &key->mNameArray[entry->mIndex];
|
||||
|
||||
if (keyValue->mIsUnichar) {
|
||||
return keyValue->mKeyStr.m2b->LowerCaseEqualsASCII(entryKey->get(),
|
||||
entryKey->Length());
|
||||
}
|
||||
|
||||
return keyValue->mKeyStr.m1b->LowerCaseEqualsASCII(entryKey->get(),
|
||||
entryKey->Length());
|
||||
return key->mIsUnichar
|
||||
? key->mKeyStr.m2b->LowerCaseEqualsASCII(name->get(), name->Length())
|
||||
: key->mKeyStr.m1b->LowerCaseEqualsASCII(name->get(), name->Length());
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -134,16 +133,20 @@ nsStaticCaseInsensitiveNameTable::nsStaticCaseInsensitiveNameTable(
|
|||
nsDependentCString* strPtr = &mNameArray[index];
|
||||
new (strPtr) nsDependentCString(raw);
|
||||
|
||||
NameTableKey key(strPtr);
|
||||
NameTableKey key(mNameArray, strPtr);
|
||||
|
||||
auto entry = static_cast<NameTableEntry*>(mNameTable.Add(&key, fallible));
|
||||
if (!entry) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NS_ASSERTION(entry->mString == 0, "Entry already exists!");
|
||||
// If the entry already exists it's unlikely but possible that its index is
|
||||
// zero, in which case this assertion won't fail. But if the index is
|
||||
// non-zero (highly likely) then it will fail. In other words, this
|
||||
// assertion is likely but not guaranteed to detect if an entry is already
|
||||
// used.
|
||||
MOZ_ASSERT(entry->mIndex == 0, "Entry already exists!");
|
||||
|
||||
entry->mString = strPtr; // not owned!
|
||||
entry->mIndex = index;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
|
@ -168,7 +171,7 @@ nsStaticCaseInsensitiveNameTable::Lookup(const nsACString& aName)
|
|||
|
||||
const nsAFlatCString& str = PromiseFlatCString(aName);
|
||||
|
||||
NameTableKey key(&str);
|
||||
NameTableKey key(mNameArray, &str);
|
||||
auto entry = static_cast<NameTableEntry*>(mNameTable.Search(&key));
|
||||
|
||||
return entry ? entry->mIndex : nsStaticCaseInsensitiveNameTable::NOT_FOUND;
|
||||
|
@ -181,7 +184,7 @@ nsStaticCaseInsensitiveNameTable::Lookup(const nsAString& aName)
|
|||
|
||||
const nsAFlatString& str = PromiseFlatString(aName);
|
||||
|
||||
NameTableKey key(&str);
|
||||
NameTableKey key(mNameArray, &str);
|
||||
auto entry = static_cast<NameTableEntry*>(mNameTable.Search(&key));
|
||||
|
||||
return entry ? entry->mIndex : nsStaticCaseInsensitiveNameTable::NOT_FOUND;
|
||||
|
|
Загрузка…
Ссылка в новой задаче