Skip to content

Commit

Permalink
Create explicit variable for initial hash value
Browse files Browse the repository at this point in the history
Summary:
Create an inline constexpr variable JenkinsHashInit that represents the
inital value of a string hash. Use this value at all existing callsites
that initialize a hash value.

Reviewed By: jpporto

Differential Revision: D43285003

fbshipit-source-id: cf83e1814067e11289082d8acb9f024a28e74f2d
  • Loading branch information
fbmal7 authored and facebook-github-bot committed Feb 22, 2023
1 parent 6e2dd65 commit eeb9917
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/hermes/Support/HashString.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ template <typename T>
uint32_t hashString(llvh::ArrayRef<T> str) {
static_assert(
sizeof(JenkinsHash) == sizeof(uint32_t), "Jenkins Hash must be 32-bit");
hermes::JenkinsHash hash = 0;
hermes::JenkinsHash hash = hermes::JenkinsHashInit;
for (const T c : str) {
hash = hermes::updateJenkinsHash(hash, c);
}
Expand Down
1 change: 1 addition & 0 deletions include/hermes/Support/JenkinsHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace hermes {

using JenkinsHash = uint32_t;
inline constexpr JenkinsHash JenkinsHashInit = 0;

namespace jenkins_details {
template <typename CharT>
Expand Down
2 changes: 1 addition & 1 deletion lib/BCGen/HBC/BytecodeDisassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ void BytecodeVisitor::visitInstructionsInBody(

class BytecodeHasher : public BytecodeVisitor {
protected:
uint32_t hash_{0};
JenkinsHash hash_{JenkinsHashInit};
bool useStrings_;
bool useIntConstants_;
uint8_t opcode_{0xff};
Expand Down
2 changes: 1 addition & 1 deletion lib/BCGen/HBC/ConsecutiveStringStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class StringPacker {
continue;
}
const CharT *chars = entry.chars_.data();
JenkinsHash hash = 0;
JenkinsHash hash = JenkinsHashInit;
size_t i = charsSize;
while (i--) {
hash = updateJenkinsHash(hash, chars[i]);
Expand Down

0 comments on commit eeb9917

Please sign in to comment.