1
0
forked from 0ad/0ad

# document issue with direct AtomFn comparison; must use strcmp instead

This was SVN commit r3844.
This commit is contained in:
janwas 2006-05-04 05:48:38 +00:00
parent cd67d271f0
commit ccafa5204e
3 changed files with 19 additions and 2 deletions

View File

@ -241,6 +241,12 @@ const char* file_make_unique_fn_copy(const char* P_fn)
} }
bool path_is_atom_fn(const char* fn)
{
return pool_contains(&atom_pool, (void*)fn);
}
void path_init() void path_init()
{ {
pool_create(&atom_pool, 8*MiB, POOL_VARIABLE_ALLOCS); pool_create(&atom_pool, 8*MiB, POOL_VARIABLE_ALLOCS);

View File

@ -73,6 +73,9 @@ struct NextNumberedFilenameInfo
extern void next_numbered_filename(const char* V_fn_fmt, extern void next_numbered_filename(const char* V_fn_fmt,
NextNumberedFilenameInfo* nfi, char* V_next_fn, bool use_vfs = true); NextNumberedFilenameInfo* nfi, char* V_next_fn, bool use_vfs = true);
extern bool path_is_atom_fn(const char* fn);
extern void path_init(); extern void path_init();
extern void path_shutdown(); extern void path_shutdown();

View File

@ -138,14 +138,22 @@ public:
template<> class DHT_Traits<const char*, TNode*> template<> class DHT_Traits<const char*, TNode*>
{ {
public: public:
static const size_t initial_entries = 16; static const size_t initial_entries = 32;
size_t hash(const char* key) const size_t hash(const char* key) const
{ {
return (size_t)fnv_lc_hash(key); return (size_t)fnv_lc_hash(key);
} }
bool equal(const char* k1, const char* k2) const bool equal(const char* k1, const char* k2) const
{ {
// exact match // note: in theory, we could take advantage of the atom_fn
// mechanism to only compare string pointers. however, we're
// dealing with path *components* here. adding these as atoms would
// about double the memory used (to ~1 MB) and require a bit of
// care in the implementation of file_make_unique_path_copy
// (must not early-out before checking the hash table).
//
// given that path components are rather short, string comparisons
// are not expensive and we'll just go with that for simplicity.
if(!strcmp(k1, k2)) if(!strcmp(k1, k2))
return true; return true;
#ifndef NDEBUG #ifndef NDEBUG