Commit c4bd0ac9 by Olli Etuaho Committed by Commit Bot

Add 32-bit hash helper to ImmutableString

Since the length of the hash is known prior to compilation, it can be compared with script-generated hashes. BUG=angleproject:2267 TEST=angle_unittests Change-Id: Ia0a78dfd450c4ea2d526da7f3495b9750dcbd1af Reviewed-on: https://chromium-review.googlesource.com/931884Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 2f7c04a3
......@@ -35,4 +35,17 @@ template <>
const size_t ImmutableString::FowlerNollVoHash<8>::kFnvOffsetBasis =
static_cast<size_t>(0xcbf29ce484222325ull);
uint32_t ImmutableString::hash32() const
{
const char *data_ptr = data();
uint32_t hash = static_cast<uint32_t>(FowlerNollVoHash<4>::kFnvOffsetBasis);
while ((*data_ptr) != '\0')
{
hash = hash ^ (*data_ptr);
hash = hash * static_cast<uint32_t>(FowlerNollVoHash<4>::kFnvPrime);
++data_ptr;
}
return hash;
}
} // namespace sh
......@@ -128,6 +128,8 @@ class ImmutableString
}
};
uint32_t hash32() const;
private:
const char *mData;
size_t mLength;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment