Commit f298b11b authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[profiler] Avoid double lookup in script map

Use the result of scripts.find() instead of using operator[] when
looking up scripts. This avoids an ugly const_cast, and avoids doing the
lookup twice.

Change-Id: I7c1a6be28928e2e3d928c389328be8785be3cff7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3056989
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75974}
parent da369852
......@@ -219,13 +219,10 @@ v8::AllocationProfile::Node* SamplingHeapProfiler::TranslateAllocationNode(
int column = v8::AllocationProfile::kNoColumnNumberInfo;
std::vector<v8::AllocationProfile::Allocation> allocations;
allocations.reserve(node->allocations_.size());
if (node->script_id_ != v8::UnboundScript::kNoScriptId &&
scripts.find(node->script_id_) != scripts.end()) {
// Cannot use std::map<T>::at because it is not available on android.
auto non_const_scripts =
const_cast<std::map<int, Handle<Script>>&>(scripts);
Handle<Script> script = non_const_scripts[node->script_id_];
if (!script.is_null()) {
if (node->script_id_ != v8::UnboundScript::kNoScriptId) {
auto script_iterator = scripts.find(node->script_id_);
if (script_iterator != scripts.end()) {
Handle<Script> script = script_iterator->second;
if (script->name().IsName()) {
Name name = Name::cast(script->name());
script_name = ToApiHandle<v8::String>(
......
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