Commit 8fb451c8 authored by Maciej Goszczycki's avatar Maciej Goszczycki Committed by Commit Bot

[cleanup] Remove isolate arument from ComputeAndSetHash

All HeapObjects already have roots access so this was redundant and
made ComputeAndSetHash difficult to use.
Eventually we need to get rid of the Isolate version of HashSeed,
but this will touch a lot of files, so leaving it for now.

Bug: v8:8562
Change-Id: I27d8fe10df72494d0a2146f408a2158cf02ce226
Reviewed-on: https://chromium-review.googlesource.com/c/1481630
Commit-Queue: Maciej Goszczycki <goszczycki@google.com>
Reviewed-by: 's avatarDan Elphick <delphick@chromium.org>
Reviewed-by: 's avatarMythri Alle <mythria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59792}
parent 2a5be38b
......@@ -17,8 +17,11 @@ namespace v8 {
namespace internal {
class Isolate;
class ReadOnlyRoots;
// TODO(v8:7464): Remove the Isolate version of this.
inline uint64_t HashSeed(Isolate* isolate);
inline uint64_t HashSeed(ReadOnlyRoots roots);
} // namespace internal
} // namespace v8
......@@ -31,9 +34,12 @@ namespace v8 {
namespace internal {
inline uint64_t HashSeed(Isolate* isolate) {
return HashSeed(ReadOnlyRoots(isolate));
}
inline uint64_t HashSeed(ReadOnlyRoots roots) {
uint64_t seed;
ReadOnlyRoots(isolate).hash_seed()->copy_out(
0, reinterpret_cast<byte*>(&seed), kInt64Size);
roots.hash_seed()->copy_out(0, reinterpret_cast<byte*>(&seed), kInt64Size);
DCHECK(FLAG_randomize_hashes || seed == 0);
return seed;
}
......
......@@ -88,10 +88,7 @@ uint32_t Name::Hash() {
uint32_t field = hash_field();
if (IsHashFieldComputed(field)) return field >> kHashShift;
// Slow case: compute hash code and set it. Has to be a string.
// Also the string must be writable, because read-only strings will have their
// hash values precomputed.
return String::cast(*this)->ComputeAndSetHash(
Isolate::FromHeap(GetHeapFromWritableObject(*this)));
return String::cast(*this)->ComputeAndSetHash();
}
bool Name::IsInterestingSymbol() const {
......
......@@ -1245,13 +1245,14 @@ bool String::IsTwoByteEqualTo(Vector<const uc16> str) {
return CompareChars(content.ToUC16Vector().start(), str.start(), slen) == 0;
}
uint32_t String::ComputeAndSetHash(Isolate* isolate) {
uint32_t String::ComputeAndSetHash() {
DisallowHeapAllocation no_gc;
// Should only be called if hash code has not yet been computed.
DCHECK(!HasHashCode());
// Store the hash code in the object.
uint32_t field = IteratingStringHasher::Hash(*this, HashSeed(isolate));
uint32_t field =
IteratingStringHasher::Hash(*this, HashSeed(GetReadOnlyRoots()));
set_hash_field(field);
// Check the hash code is there.
......
......@@ -450,7 +450,7 @@ class String : public Name {
V8_EXPORT_PRIVATE bool SlowAsArrayIndex(uint32_t* index);
// Compute and set the hash code.
uint32_t ComputeAndSetHash(Isolate* isolate);
uint32_t ComputeAndSetHash();
OBJECT_CONSTRUCTORS(String, Name);
};
......
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