From 32f335ca11e9fde0aac87a5b5794ccbf6191fd2e Mon Sep 17 00:00:00 2001 From: Hans Fugal Date: Thu, 8 Jan 2015 14:46:26 -0800 Subject: [PATCH] avoid std::_Hash_impl 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 | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/folly/wangle/acceptor/DomainNameMisc.h b/folly/wangle/acceptor/DomainNameMisc.h index 41c4c741..4560a716 100644 --- a/folly/wangle/acceptor/DomainNameMisc.h +++ b/folly/wangle/acceptor/DomainNameMisc.h @@ -57,14 +57,11 @@ struct dn_char_traits : public std::char_traits { typedef std::basic_string DNString; struct DNStringHash : public std::hash { - size_t operator()(const DNString& s) const noexcept { - size_t h = static_cast(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()(s2); } }; -- 2.34.1