Remove superfluous std::move
[folly.git] / folly / Hash.h
index 7e44fbb2dec986cedebce4e5e8bf72452338c967..0f0afc5baf71ac4c4ca301becf5f84e98fca6da5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -14,8 +14,7 @@
  * limitations under the License.
  */
 
-#ifndef FOLLY_BASE_HASH_H_
-#define FOLLY_BASE_HASH_H_
+#pragma once
 
 #include <cstdint>
 #include <cstring>
@@ -25,6 +24,7 @@
 #include <utility>
 
 #include <folly/ApplyTuple.h>
+#include <folly/Bits.h>
 #include <folly/SpookyHashV1.h>
 #include <folly/SpookyHashV2.h>
 
@@ -277,11 +277,11 @@ inline uint64_t fnv64(const std::string& str,
  * Paul Hsieh: http://www.azillionmonkeys.com/qed/hash.html
  */
 
-#define get16bits(d) (*((const uint16_t*) (d)))
+#define get16bits(d) folly::loadUnaligned<uint16_t>(d)
 
 inline uint32_t hsieh_hash32_buf(const void* buf, size_t len) {
   // forcing signed char, since other platforms can use unsigned
-  const signed char* s = reinterpret_cast<const signed char*>(buf);
+  const unsigned char* s = reinterpret_cast<const unsigned char*>(buf);
   uint32_t hash = static_cast<uint32_t>(len);
   uint32_t tmp;
   size_t rem;
@@ -361,6 +361,14 @@ struct Hash {
   }
 };
 
+template <>
+struct hasher<bool> {
+  size_t operator()(bool key) const {
+    // Make sure that all the output bits depend on the input.
+    return -static_cast<size_t>(key);
+  }
+};
+
 template<> struct hasher<int32_t> {
   size_t operator()(int32_t key) const {
     return hash::jenkins_rev_mix32(uint32_t(key));
@@ -459,5 +467,3 @@ namespace std {
     }
   };
 } // namespace std
-
-#endif