diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-06-03 12:43:38 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-03 14:47:15 +0100 |
commit | 8b449214aff2f5a9ee17f42bb0a6049f2173aba0 (patch) | |
tree | 8faa71c45e0143b3c4f2fdd690567e4a13804222 /Userland/Libraries/LibJS/Runtime/Exception.cpp | |
parent | bc8d16ad28afb7436bfde1fd0a21faf73d652230 (diff) | |
download | serenity-8b449214aff2f5a9ee17f42bb0a6049f2173aba0.zip |
LibJS: Optimize insertion order in the Exception constructor
By inserting the stack frames in the correct order we can improve the
runtime for the test-js test suite by about 20%.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Exception.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Exception.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Exception.cpp b/Userland/Libraries/LibJS/Runtime/Exception.cpp index fa59a07e54..a3fd15a1f2 100644 --- a/Userland/Libraries/LibJS/Runtime/Exception.cpp +++ b/Userland/Libraries/LibJS/Runtime/Exception.cpp @@ -18,18 +18,18 @@ Exception::Exception(Value value) { auto& vm = this->vm(); m_traceback.ensure_capacity(vm.call_stack().size()); - for (auto* call_frame : vm.call_stack()) { + for (ssize_t i = vm.call_stack().size() - 1; i >= 0; i--) { + auto* call_frame = vm.call_stack()[i]; auto function_name = call_frame->function_name; if (function_name.is_empty()) function_name = "<anonymous>"; - m_traceback.prepend({ - .function_name = move(function_name), + m_traceback.empend( + move(function_name), // We might not have an AST node associated with the call frame, e.g. in promise // reaction jobs (which aren't called anywhere from the source code). // They're not going to generate any _unhandled_ exceptions though, so a meaningless // source range is fine. - .source_range = call_frame->current_node ? call_frame->current_node->source_range() : SourceRange {}, - }); + call_frame->current_node ? call_frame->current_node->source_range() : SourceRange {}); } } |