From d16fab5815f2f7b454c15d5aea36346c511e0eed Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 24 Nov 2022 15:38:52 +0100 Subject: [PATCH] LibJS: Avoid unnecessary SourceRange construction in parse_program() This takes `test-js` runtime from 4.3 sec to 4.1 sec on my machine. --- Userland/Libraries/LibJS/AST.h | 4 +++- Userland/Libraries/LibJS/Parser.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibJS/AST.h b/Userland/Libraries/LibJS/AST.h index 47bd74a9273..f01f6c1917d 100644 --- a/Userland/Libraries/LibJS/AST.h +++ b/Userland/Libraries/LibJS/AST.h @@ -53,7 +53,9 @@ public: virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const; virtual void dump(int indent) const; - SourceRange source_range() const; + [[nodiscard]] SourceRange source_range() const; + + void set_end_offset(Badge, u32 end_offset) { m_end_offset = end_offset; } String class_name() const; diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index ec5387b1fab..0baff40228c 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -497,7 +497,7 @@ NonnullRefPtr Parser::parse_program(bool starts_in_strict_mode) else parse_module(program); - program->source_range().end = position(); + program->set_end_offset({}, position().offset); return program; }