-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[vm] Fix Instance::IdentityHashCode for strings
This method should return the same value as `String::Hash` to not be misaligned with how `identityHashCode()` is implemented. On 64bit platforms we also use the same location in the object header to store identity hash and string hash so these two can't be misaligned. Fixes #56749 TEST=vm/cc/String,vm/dart/regress_56749 [email protected] Change-Id: I221cc8ad85f7ffb7f7d2bcdd0f4341c3ecf25663 Fixed: 56749 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385860 Commit-Queue: Slava Egorov <[email protected]> Reviewed-by: Ryan Macnak <[email protected]>
- Loading branch information
Showing
3 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import "package:expect/expect.dart"; | ||
|
||
void main() { | ||
String a = "Hello, world!"; | ||
String b = a.substring(0, 5) + a.substring(5); | ||
|
||
// `Closure::ComputeHash` will invoke `Instance::IdentityHashCode` on | ||
// the receiver (b). Previously this function did not handle String | ||
// specially and used a random hash code instead of the expected | ||
// content-based hash code. | ||
print(b.toString.hashCode); | ||
|
||
Expect.equals(a.hashCode, b.hashCode); | ||
Expect.equals(a, b); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters