diff options
author | Evan Martin <martine@danga.com> | 2011-09-12 18:44:12 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2011-09-12 18:46:18 (GMT) |
commit | 3fbb25b2cc66f236a39b728d20e5d44da23612ac (patch) | |
tree | d6eb7c1bc63ef3d4d4d1056750756dc581da5ef0 /src/hash_map.h | |
parent | f1139aff5deddacd899be064fad9ed5a185e7444 (diff) | |
download | Ninja-3fbb25b2cc66f236a39b728d20e5d44da23612ac.zip Ninja-3fbb25b2cc66f236a39b728d20e5d44da23612ac.tar.gz Ninja-3fbb25b2cc66f236a39b728d20e5d44da23612ac.tar.bz2 |
generalize the pattern of hash_map<const char*, ...>, use in BuildLog
Refactor the code in StatCache for use in BuildLog. Now both use
hash tables where the keys are const char*. Removes another 30ms
from Chrome no-op builds.
Diffstat (limited to 'src/hash_map.h')
-rw-r--r-- | src/hash_map.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/hash_map.h b/src/hash_map.h index 346a34e..1025f71 100644 --- a/src/hash_map.h +++ b/src/hash_map.h @@ -15,6 +15,8 @@ #ifndef NINJA_MAP_H_ #define NINJA_MAP_H_ +#include <string.h> + #ifdef _MSC_VER #include <hash_map> @@ -37,4 +39,31 @@ struct hash<std::string> { #endif +/// Equality binary predicate for const char*. +struct ExternalStringEq { + bool operator()(const char* a, const char* b) { + return strcmp(a, b) == 0; + } +}; + +/// Hash functor for const char*. +struct ExternalStringHash { + size_t operator()(const char* key) const { +#ifdef _MSC_VER + return stdext::hash<const char*>()(key); +#else + return __gnu_cxx::hash<const char*>()(key); +#endif + } +}; + +/// A template for hash_maps keyed by a const char* that is maintained within +/// the values. Use like: +/// ExternalStringHash<Foo*>::Type foos; +/// to make foos into a hash mapping const char* => Foo*. +template<typename V> +struct ExternalStringHashMap { + typedef hash_map<const char*, V, ExternalStringHash, ExternalStringEq> Type; +}; + #endif // NINJA_MAP_H_ |