Commit 678afa3c authored by Andrew Comminos's avatar Andrew Comminos Committed by Commit Bot

[cpu-profiler] Fix string length calculation for GetConsName

Currently, GetConsName incorrectly includes the null terminator as part
of the length used in the string's hash. Exclude this to be consistent
with GetCopy, GetName, etc. and permit coalescing.

Bug: v8:0
Change-Id: I1e8a4eb7055637f3ed178014725b44e84d7788b6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2578192Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Commit-Queue: Andrew Comminos <acomminos@fb.com>
Cr-Commit-Position: refs/heads/master@{#71667}
parent 0b7769e3
......@@ -101,7 +101,7 @@ const char* StringsStorage::GetConsName(const char* prefix, Name name) {
char* cons_result = NewArray<char>(cons_length);
snprintf(cons_result, cons_length, "%s%s", prefix, data.get());
return AddOrDisposeString(cons_result, cons_length);
return AddOrDisposeString(cons_result, cons_length - 1);
} else if (name.IsSymbol()) {
return "<symbol>";
}
......
......@@ -157,5 +157,17 @@ TEST_F(StringsStorageWithIsolate, InvalidRelease) {
#endif // DEBUG
}
TEST_F(StringsStorageWithIsolate, CopyAndConsShareStorage) {
StringsStorage storage;
Handle<String> str = isolate()->factory()->NewStringFromAsciiChecked("foo");
const char* copy_str = storage.GetCopy("get foo");
const char* cons_str = storage.GetConsName("get ", *str);
CHECK_EQ(storage.GetStringCountForTesting(), 1);
CHECK_EQ(copy_str, cons_str);
}
} // namespace internal
} // namespace v8
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