--- deliantra/server/common/arch.C 2006/11/07 16:30:54 1.25 +++ deliantra/server/common/arch.C 2006/11/17 19:40:53 1.26 @@ -23,19 +23,17 @@ #include -#include - #include -#include #include #include -/* IF set, does a little timing on the archetype load. */ -#define TIME_ARCH_LOAD 0 +#define USE_UNORDERED_MAP 0 -static void add_arch (archetype *at); +#if USE_UNORDERED_MAP +# include +# include +#endif -static archetype *arch_table[ARCHTABLE]; int arch_cmp = 0; /* How many strcmp's */ int arch_search = 0; /* How many searches */ int arch_init; /* True if doing arch initialization */ @@ -53,14 +51,16 @@ typedef std::tr1::unordered_map < std::size_t, - archetype *, - std::hash, + arch_ptr, + std::tr1::hash, std::equal_to, slice_allocator< std::pair > true, > HT; static HT ht; +#else +static arch_ptr arch_table[ARCHTABLE]; #endif /** @@ -360,7 +360,7 @@ LOG (llevDebug, " Setting up archetable...\n"); for (at = first_archetype; at != NULL; at = (at->more == NULL) ? at->next : at->more) - add_arch (at); + at->hash_add (); LOG (llevDebug, "done\n"); } @@ -383,6 +383,7 @@ i++; } + LOG (llevDebug, "Freed %d archetypes, %d faces\n", i, f); } @@ -554,12 +555,6 @@ { char filename[MAX_BUF]; -#if TIME_ARCH_LOAD - struct timeval - tv1, - tv2; -#endif - sprintf (filename, "%s/%s", settings.datadir, settings.archetypes); LOG (llevDebug, "Reading archetypes from %s:\n", filename); @@ -733,22 +728,21 @@ /* * Adds an archetype to the hashtable. */ - -static void -add_arch (archetype *at) +void +archetype::hash_add () { #if USE_UNORDERED_MAP - ht.insert (std::make_pair ((size_t) (const char *) at->name, at)); -#endif + ht.insert (std::make_pair ((size_t) (const char *) name, this)); +#else - int index = hasharch ((const char *) at->name, ARCHTABLE), org_index = index; + int index = hasharch ((const char *) name, ARCHTABLE), org_index = index; for (;;) { - if (arch_table[index] == NULL) + if (!arch_table[index]) { - arch_table[index] = at; - return; + arch_table[index] = this; + break; } if (++index == ARCHTABLE) @@ -757,6 +751,33 @@ if (index == org_index) fatal (ARCHTABLE_TOO_SMALL); } +#endif +} + +void +archetype::hash_del () +{ +#if USE_UNORDERED_MAP +# error remove this from HT +#else + + int index = hasharch ((const char *) name, ARCHTABLE), org_index = index; + + for (;;) + { + if (arch_table[index] == this) + { + arch_table[index] = 0; + break; + } + + if (++index == ARCHTABLE) + index = 0; + + if (index == org_index) + break; + } +#endif } /*