Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1765)

Unified Diff: runtime/platform/hashmap.h

Issue 50983002: Implement fromEnvironment on bool, int and String (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/platform/hashmap.h
diff --git a/runtime/platform/hashmap.h b/runtime/platform/hashmap.h
index 01fad72157fe69ca23cbcaca1f05a273d6b30bbb..d5a02930f45f4c780c89229ba293f48aba1c231b 100644
--- a/runtime/platform/hashmap.h
+++ b/runtime/platform/hashmap.h
@@ -17,6 +17,27 @@ class HashMap {
return key1 == key2;
}
+ static uint32_t StringHash(char* key) {
+ uint32_t hash_ = 0;
+ if (key == NULL) return hash_;
+ int len = strlen(key);
+ for (int i = 0; i < len; i++) {
+ hash_ += key[i];
+ hash_ += hash_ << 10;
+ hash_ ^= hash_ >> 6;
+ }
+ hash_ += hash_ << 3;
+ hash_ ^= hash_ >> 11;
+ hash_ += hash_ << 15;
+ return hash_ == 0 ? 1 : hash_;
+ }
+
+ static bool SameStringValue(void* key1, void* key2) {
+ return strcmp(reinterpret_cast<char*>(key1),
+ reinterpret_cast<char*>(key2)) == 0;
+ }
+
+
// initial_capacity is the size of the initial hash map;
// it must be a power of 2 (and thus must not be 0).
HashMap(MatchFun match, uint32_t initial_capacity);

Powered by Google App Engine
This is Rietveld 408576698