From df435a8983a5c1d1c327a4a2a19836a13aff267b Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 20 Aug 2012 02:46:45 +0300 Subject: [PATCH] Use the hash function from mspcore Constructing tags mostly happens when loading datafiles or otherwise outside the rendering loop, so the small extra overhead from a cross-library function call is not significant. Renderables that wish to compare the Tag against a fixed value should avoid constructing the reference Tag on every render call anyway. --- source/tag.cpp | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/source/tag.cpp b/source/tag.cpp index af92bbb8..c5824aec 100644 --- a/source/tag.cpp +++ b/source/tag.cpp @@ -1,27 +1,16 @@ +#include +#include #include "tag.h" -namespace { - -template -inline unsigned hash(T begin, T end) -{ - unsigned result = 0; - for(T i=begin; (i!=end && *i); ++i) - result = ((result>>29)|(result<<5))^static_cast(*i); - return result; -} - -} - namespace Msp { namespace GL { Tag::Tag(const char *s): - id(s ? hash(s, 0) : 0) + id((s && *s) ? hash32(s, strlen(s)) : 0) { } Tag::Tag(const std::string &s): - id(hash(s.begin(), s.end())) + id(s.empty() ? 0 : hash32(s)) { } } // namespace GL -- 2.45.2