]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
hash: use std::hash for string hashing
authorJustin Viiret <justin.viiret@intel.com>
Thu, 10 Aug 2017 06:58:48 +0000 (16:58 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Mon, 18 Sep 2017 03:26:18 +0000 (13:26 +1000)
src/util/hash.h

index 1c35d20c3872a5ca9bf08c83eac39d7245f337f3..60bc670abbf312445a61fcaa6afcd8d2172b0886 100644 (file)
@@ -35,6 +35,7 @@
 #define UTIL_HASH_H
 
 #include <functional>
+#include <string>
 #include <type_traits>
 #include <utility>
 
@@ -123,10 +124,16 @@ struct ue2_hash<T, typename std::enable_if<has_hash_member<T>::value>::type> {
     }
 };
 
-/** \brief Hash for any container type that supports std::begin(). */
+/**
+ * \brief Hash for any container type that supports std::begin().
+ *
+ * We exempt std::string as std::hash<std:string> is provided and quicker.
+ */
 template<typename T>
-struct ue2_hash<T, typename std::enable_if<is_container<T>::value &&
-                                           !has_hash_member<T>::value>::type> {
+struct ue2_hash<T, typename std::enable_if<
+           is_container<T>::value &&
+           !std::is_same<typename std::decay<T>::type, std::string>::value &&
+           !has_hash_member<T>::value>::type> {
     size_t operator()(const T &obj) const {
         size_t v = 0;
         for (const auto &elem : obj) {