зеркало из https://github.com/mozilla/gecko-dev.git
Bug 940315 - Don't use a generic hash function to generate database filename. r=janv
This commit is contained in:
Родитель
8a469f49cb
Коммит
a7e395a2b8
|
@ -63,11 +63,36 @@ MakeSchemaVersion(uint32_t aMajorSchemaVersion,
|
|||
const int32_t kSQLiteSchemaVersion = int32_t((kMajorSchemaVersion << 4) +
|
||||
kMinorSchemaVersion);
|
||||
|
||||
const uint32_t kGoldenRatioU32 = 0x9E3779B9U;
|
||||
|
||||
inline
|
||||
uint32_t
|
||||
RotateBitsLeft32(uint32_t value, uint8_t bits)
|
||||
{
|
||||
MOZ_ASSERT(bits < 32);
|
||||
return (value << bits) | (value >> (32 - bits));
|
||||
}
|
||||
|
||||
inline
|
||||
uint32_t
|
||||
HashName(const nsAString& aName)
|
||||
{
|
||||
const char16_t* str = aName.BeginReading();
|
||||
size_t length = aName.Length();
|
||||
|
||||
uint32_t hash = 0;
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
hash = kGoldenRatioU32 * (RotateBitsLeft32(hash, 5) ^ str[i]);
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
nsresult
|
||||
GetDatabaseFilename(const nsAString& aName,
|
||||
nsAString& aDatabaseFilename)
|
||||
{
|
||||
aDatabaseFilename.AppendInt(HashString(aName));
|
||||
aDatabaseFilename.AppendInt(HashName(aName));
|
||||
|
||||
nsCString escapedName;
|
||||
if (!NS_Escape(NS_ConvertUTF16toUTF8(aName), escapedName, url_XPAlphas)) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче