summaryrefslogtreecommitdiffstats
path: root/src/hash_map.h
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2012-01-11 18:22:50 (GMT)
committerEvan Martin <martine@danga.com>2012-01-11 18:22:50 (GMT)
commit292c0d42d0953a6f4d2e3a8a37426ae18355c759 (patch)
treeb1fc710f1bc2b86da700ce1cf60d153426b294c2 /src/hash_map.h
parente8610adb68fe7ec45c158ce970cb37e1d88e750b (diff)
downloadNinja-292c0d42d0953a6f4d2e3a8a37426ae18355c759.zip
Ninja-292c0d42d0953a6f4d2e3a8a37426ae18355c759.tar.gz
Ninja-292c0d42d0953a6f4d2e3a8a37426ae18355c759.tar.bz2
make new hash work on windows
Diffstat (limited to 'src/hash_map.h')
-rw-r--r--src/hash_map.h18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/hash_map.h b/src/hash_map.h
index dc08d61..d3e9c51 100644
--- a/src/hash_map.h
+++ b/src/hash_map.h
@@ -67,9 +67,19 @@ static inline size_t StlHash(StringPiece str) {
using stdext::hash_map;
using stdext::hash_compare;
-struct ExternalStringCmp {
- bool operator()(const char* a, const char* b) const {
- return strcmp(a, b) < 0;
+struct StringPieceCmp : public hash_compare<StringPiece> {
+ size_t operator()(const StringPiece& key) const {
+ return MurmurHash2(key.str_, key.len_, kSeed);
+ }
+ bool operator()(const StringPiece& a, const StringPiece& b) const {
+ int cmp = strncmp(a.str_, b.str_, min(a.len_, b.len_));
+ if (cmp < 0) {
+ return true;
+ } else if (cmp > 0) {
+ return false;
+ } else {
+ return a.len_ < b.len_;
+ }
}
};
@@ -104,7 +114,7 @@ struct hash<StringPiece> {
template<typename V>
struct ExternalStringHashMap {
#ifdef _MSC_VER
- typedef hash_map<const char*, V, hash_compare<const char *,ExternalStringCmp> > Type;
+ typedef hash_map<StringPiece, V, StringPieceCmp> Type;
#else
typedef hash_map<StringPiece, V> Type;
#endif