diff options
author | Andreas Kling <kling@serenityos.org> | 2021-05-14 11:37:46 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-14 11:38:35 +0200 |
commit | 6210d2612ebf690800e8bf59b41218da784acba8 (patch) | |
tree | 8b09460c248fe7c52fe89959982206d9012e1e85 | |
parent | 8360079cac2e75b15bf9ec264aa61f8776d1c832 (diff) | |
download | serenity-6210d2612ebf690800e8bf59b41218da784acba8.zip |
Profiler: Avoid JsonArray copying during perfcore parsing
Use JsonObject::get_ptr() to access array values without copying them.
-rw-r--r-- | Userland/DevTools/Profiler/Profile.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Userland/DevTools/Profiler/Profile.cpp b/Userland/DevTools/Profiler/Profile.cpp index b422531869..c525d7972b 100644 --- a/Userland/DevTools/Profiler/Profile.cpp +++ b/Userland/DevTools/Profiler/Profile.cpp @@ -212,11 +212,11 @@ Result<NonnullOwnPtr<Profile>, String> Profile::load_from_perfcore_file(const St if (!file_or_error.is_error()) kernel_elf = make<ELF::Image>(file_or_error.value()->bytes()); - auto events_value = object.get("events"); - if (!events_value.is_array()) + auto events_value = object.get_ptr("events"); + if (!events_value || !events_value->is_array()) return String { "Malformed profile (events is not an array)" }; - auto& perf_events = events_value.as_array(); + auto& perf_events = events_value->as_array(); NonnullOwnPtrVector<Process> all_processes; HashMap<pid_t, Process*> current_processes; @@ -299,7 +299,9 @@ Result<NonnullOwnPtr<Profile>, String> Profile::load_from_perfcore_file(const St continue; } - auto stack_array = perf_event.get("stack").as_array(); + auto* stack = perf_event.get_ptr("stack"); + VERIFY(stack); + auto& stack_array = stack->as_array(); for (ssize_t i = stack_array.values().size() - 1; i >= 0; --i) { auto& frame = stack_array.at(i); auto ptr = frame.to_number<u32>(); |