From d4b95e81b40a88af556b6dd9132f0074a044708b Mon Sep 17 00:00:00 2001 From: hiker Date: Thu, 23 Jan 2014 09:54:48 +1100 Subject: [PATCH] Moved hash function from StringUtils into player, there is no other use of that function. --- src/config/player.cpp | 25 ++++++++++++++++--------- src/utils/string_utils.cpp | 13 ------------- src/utils/string_utils.hpp | 3 --- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/config/player.cpp b/src/config/player.cpp index 179c30775..a58ca09cf 100644 --- a/src/config/player.cpp +++ b/src/config/player.cpp @@ -36,9 +36,9 @@ PlayerProfile::PlayerProfile(const core::stringw& name) : #endif int64_t unique_id = generateUniqueId(core::stringc(name.c_str()).c_str()); - std::ostringstream tostring; - tostring << std::hex << unique_id; - m_unique_id = tostring.str(); + std::ostringstream to_string; + to_string << std::hex << unique_id; + m_unique_id = to_string.str(); } //------------------------------------------------------------------------------ @@ -67,19 +67,26 @@ PlayerProfile::PlayerProfile(const XMLNode* node) : #ifdef DEBUG m_magic_number = 0xABCD1234; #endif -} +} // PlayerProfile //------------------------------------------------------------------------------ void PlayerProfile::incrementUseFrequency() { if (m_is_guest_account) m_use_frequency = -1; else m_use_frequency++; -} +} // incrementUseFrequency //------------------------------------------------------------------------------ -int64_t PlayerProfile::generateUniqueId(const char* playerName) +int64_t PlayerProfile::generateUniqueId(const char* player_name) { + // First create a simple hash based on he player name + int hash = 0; + for (int n=0; player_name[n] != 0; n++) + { + hash += (hash << (hash & 0xF)) ^ player_name[n]; + } + return ((int64_t)(StkTime::getTimeSinceEpoch()) << 32) | - ((rand() << 16) & 0xFFFF0000) | - (StringUtils::simpleHash(playerName) & 0xFFFF); -} + ((rand() << 16) & 0xFFFF0000) | + hash; +} // generateUniqueId diff --git a/src/utils/string_utils.cpp b/src/utils/string_utils.cpp index cc73bfad8..ae413d1ef 100644 --- a/src/utils/string_utils.cpp +++ b/src/utils/string_utils.cpp @@ -665,19 +665,6 @@ namespace StringUtils return output.str(); } // encodeToHtmlEntities - // ------------------------------------------------------------------------ - - unsigned int simpleHash(const char* input) - { - int hash = 0; - for (int n=0; input[n] != 0; n++) - { - hash += (hash << (hash & 0xF)) ^ input[n]; - } - - return hash; - } - // ------------------------------------------------------------------------ /** Converts a version string (in the form of 'X.Y.Za-rcU' into an * integer number. diff --git a/src/utils/string_utils.hpp b/src/utils/string_utils.hpp index 355dfa841..ee46848ea 100644 --- a/src/utils/string_utils.hpp +++ b/src/utils/string_utils.hpp @@ -61,9 +61,6 @@ namespace StringUtils std::string encodeToHtmlEntities(const irr::core::stringw &output); - /** Compute a simple hash of a string */ - unsigned int simpleHash(const char* input); - // ------------------------------------------------------------------------ template std::string toString (const T& any)