From f72e61be06817d7126e302a65311be87d9606746 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Thu, 29 Dec 2011 13:06:12 +0100 Subject: [PATCH] Optimize string->enum conversion (issue #345, thanks Kai) --- src/common/StringMap.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/common/StringMap.h b/src/common/StringMap.h index 895fcf541..13d5ee811 100644 --- a/src/common/StringMap.h +++ b/src/common/StringMap.h @@ -80,15 +80,18 @@ namespace love bool find(const char * key, T & t) { - //unsigned str_hash = djb2(key); + unsigned str_hash = djb2(key); for (unsigned i = 0; i < MAX; ++i) { - //unsigned str_i = (str_hash + i) % MAX; //this isn't used, is this intentional? + unsigned str_i = (str_hash + i) % MAX; //this isn't used, is this intentional? - if (records[i].set && streq(records[i].key, key)) + if (!records[str_i].set) + return false; + + if (streq(records[str_i].key, key)) { - t = records[i].value; + t = records[str_i].value; return true; } }