avoid std::_Hash_impl
authorHans Fugal <fugalh@fb.com>
Thu, 8 Jan 2015 22:46:26 +0000 (14:46 -0800)
committerViswanath Sivakumar <viswanath@fb.com>
Tue, 13 Jan 2015 19:01:05 +0000 (11:01 -0800)
Summary:
Default Yosemite clang has no `std::_Hash_impl`, which is an internal implementation detail anyway.

@davejwatson you might have a different suggestion about how to implement this without that function, or how to test if it exists and do this only if it doesn't. This is probably not the most efficient approach, since it copies the string.

Test Plan:
builds
inspection
fbgs doesn't turn up many results (only recent wangle ssl code really) so I don't think this will be a big perf regression if we just go with it. But if I'm wrong, we can gate it on `#if __APPLE__` or something.

Reviewed By: davejwatson@fb.com

Subscribers: folly-diffs@, fugalh, exa, davejwatson

FB internal diff: D1767052

Signature: t1:1767052:1420738784:e219ebff7aec8682b24c15a03b47077e1559c1ab

folly/wangle/acceptor/DomainNameMisc.h

index 41c4c741f4d3c76119687f72f013918af7578c9b..4560a71633bd85ba4ca06ed53fc835a957673c09 100644 (file)
@@ -57,14 +57,11 @@ struct dn_char_traits : public std::char_traits<char> {
 typedef std::basic_string<char, dn_char_traits> DNString;
 
 struct DNStringHash : public std::hash<std::string> {
-  size_t operator()(const DNString& s) const noexcept {
-    size_t h = static_cast<size_t>(0xc70f6907UL);
-    const char* d = s.data();
-    for (size_t i = 0; i < s.length(); ++i) {
-      char a = ::tolower(*d++);
-      h = std::_Hash_impl::hash(&a, sizeof(a), h);
-    }
-    return h;
+  size_t operator()(const DNString& s1) const noexcept {
+    std::string s2(s1.data(), s1.size());
+    for (char& c : s2)
+      c = ::tolower(c);
+    return std::hash<std::string>()(s2);
   }
 };