diff --git a/headers/private/package/hpkg/Strings.h b/headers/private/package/hpkg/Strings.h index dcd4da9e4d..31ec21f55f 100644 --- a/headers/private/package/hpkg/Strings.h +++ b/headers/private/package/hpkg/Strings.h @@ -8,6 +8,7 @@ #include +#include #include @@ -18,9 +19,6 @@ namespace BHPKG { namespace BPrivate { -uint32 hash_string(const char* string); - - struct CachedString { char* string; int32 index; @@ -57,7 +55,7 @@ struct CachedStringHashDefinition { size_t HashKey(const char* key) const { - return hash_string(key); + return BString::HashValue(key); } size_t Hash(const CachedString* value) const diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp index e05bc4e98f..8e0828ab41 100644 --- a/src/apps/webpositive/BrowserWindow.cpp +++ b/src/apps/webpositive/BrowserWindow.cpp @@ -1813,7 +1813,7 @@ BrowserWindow::AuthenticationChallenge(BString message, BString& inOutUser, = CredentialsStorage::SessionInstance(); // TODO: Using the message as key here is not so smart. - HashKeyString key(message); + HashString key(message); if (failureCount == 0) { if (persistentStorage->Contains(key)) { diff --git a/src/apps/webpositive/CredentialsStorage.cpp b/src/apps/webpositive/CredentialsStorage.cpp index bd5498b5a7..6e79ce1682 100644 --- a/src/apps/webpositive/CredentialsStorage.cpp +++ b/src/apps/webpositive/CredentialsStorage.cpp @@ -158,7 +158,7 @@ CredentialsStorage::PersistentInstance() bool -CredentialsStorage::Contains(const HashKeyString& key) +CredentialsStorage::Contains(const HashString& key) { BAutolock _(this); @@ -167,7 +167,7 @@ CredentialsStorage::Contains(const HashKeyString& key) status_t -CredentialsStorage::PutCredentials(const HashKeyString& key, +CredentialsStorage::PutCredentials(const HashString& key, const Credentials& credentials) { BAutolock _(this); @@ -177,7 +177,7 @@ CredentialsStorage::PutCredentials(const HashKeyString& key, Credentials -CredentialsStorage::GetCredentials(const HashKeyString& key) +CredentialsStorage::GetCredentials(const HashString& key) { BAutolock _(this); @@ -226,7 +226,7 @@ CredentialsStorage::_SaveSettings() const const CredentialMap::Entry& entry = iterator.Next(); if (entry.value.Archive(&credentialsArchive) != B_OK || credentialsArchive.AddString("key", - entry.key.value) != B_OK) { + entry.key.GetString()) != B_OK) { break; } if (settingsArchive.AddMessage("credentials", diff --git a/src/apps/webpositive/CredentialsStorage.h b/src/apps/webpositive/CredentialsStorage.h index 26767ae62d..a5377bfe95 100644 --- a/src/apps/webpositive/CredentialsStorage.h +++ b/src/apps/webpositive/CredentialsStorage.h @@ -6,11 +6,13 @@ #ifndef CREDENTIAL_STORAGE_H #define CREDENTIAL_STORAGE_H -#include "HashKeys.h" -#include "HashMap.h" + #include #include +#include "HashMap.h" +#include "HashString.h" + class BFile; class BMessage; @@ -48,10 +50,10 @@ public: static CredentialsStorage* SessionInstance(); static CredentialsStorage* PersistentInstance(); - bool Contains(const HashKeyString& key); - status_t PutCredentials(const HashKeyString& key, + bool Contains(const BPrivate::HashString& key); + status_t PutCredentials(const HashString& key, const Credentials& credentials); - Credentials GetCredentials(const HashKeyString& key); + Credentials GetCredentials(const HashString& key); private: CredentialsStorage(bool persistent); @@ -63,7 +65,7 @@ private: uint32 mode) const; private: - typedef HashMap CredentialMap; + typedef HashMap CredentialMap; CredentialMap fCredentialMap; static CredentialsStorage sPersistentInstance; @@ -74,4 +76,3 @@ private: #endif // CREDENTIAL_STORAGE_H - diff --git a/src/apps/webpositive/support/HashKeys.h b/src/apps/webpositive/support/HashKeys.h deleted file mode 100644 index 3480b56492..0000000000 --- a/src/apps/webpositive/support/HashKeys.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 2010, Stephan Aßmus . All rights reserved. - * Copyright 2004-2007, Ingo Weinhold . All rights reserved. - * Distributed under the terms of the MIT License. - */ -#ifndef HASH_KEYS_H -#define HASH_KEYS_H - -#include - - -namespace BPrivate { - -#if 0 -// TODO: Move here from HashMap.h and adapt all clients. -// HashKey32 -template -struct HashKey32 { - HashKey32() {} - HashKey32(const Value& value) : value(value) {} - - uint32 GetHashCode() const - { - return (uint32)value; - } - - HashKey32 operator=(const HashKey32& other) - { - value = other.value; - return *this; - } - - bool operator==(const HashKey32& other) const - { - return (value == other.value); - } - - bool operator!=(const HashKey32& other) const - { - return (value != other.value); - } - - Value value; -}; - - -// HashKey64 -template -struct HashKey64 { - HashKey64() {} - HashKey64(const Value& value) : value(value) {} - - uint32 GetHashCode() const - { - uint64 v = (uint64)value; - return (uint32)(v >> 32) ^ (uint32)v; - } - - HashKey64 operator=(const HashKey64& other) - { - value = other.value; - return *this; - } - - bool operator==(const HashKey64& other) const - { - return (value == other.value); - } - - bool operator!=(const HashKey64& other) const - { - return (value != other.value); - } - - Value value; -}; -#endif - - -struct HashKeyString { - HashKeyString() {} - HashKeyString(const BString& value) : value(value) {} - HashKeyString(const char* string) : value(string) {} - - uint32 GetHashCode() const - { - // from the Dragon Book: a slightly modified hashpjw() - uint32 hash = 0; - const char* string = value.String(); - if (string != NULL) { - for (; *string; string++) { - uint32 g = hash & 0xf0000000; - if (g != 0) - hash ^= g >> 24; - hash = (hash << 4) + *string; - } - } - return hash; - } - - HashKeyString operator=(const HashKeyString& other) - { - value = other.value; - return *this; - } - - bool operator==(const HashKeyString& other) const - { - return (value == other.value); - } - - bool operator!=(const HashKeyString& other) const - { - return (value != other.value); - } - - BString value; -}; - -} // namespace BPrivate - -using BPrivate::HashKeyString; - -#endif // HASH_KEYS_H diff --git a/src/bin/package/command_extract.cpp b/src/bin/package/command_extract.cpp index a786c07b84..a386b784b3 100644 --- a/src/bin/package/command_extract.cpp +++ b/src/bin/package/command_extract.cpp @@ -260,7 +260,7 @@ private: size_t HashKey(const char* key) const { - return string_hash(key); + return BString::HashValue(key); } size_t Hash(const Entry* value) const diff --git a/src/kits/package/hpkg/Strings.cpp b/src/kits/package/hpkg/Strings.cpp index 32210fd2f4..45d41c0a1c 100644 --- a/src/kits/package/hpkg/Strings.cpp +++ b/src/kits/package/hpkg/Strings.cpp @@ -14,26 +14,6 @@ namespace BHPKG { namespace BPrivate { -// from the Dragon Book: a slightly modified hashpjw() -uint32 -hash_string(const char* string) -{ - if (string == NULL) - return 0; - - uint32 h = 0; - - for (; *string; string++) { - uint32 g = h & 0xf0000000; - if (g) - h ^= g >> 24; - h = (h << 4) + *string; - } - - return h; -} - - StringCache::StringCache() { }