Forráskód Böngészése

LibJS/Bytecode: Avoid Value==Value in Call built-in fast path

Comparing two Values has to call the generic same_value() helper,
and we can avoid this by simply using a stronger type for built-in
native function handlers.
Andreas Kling 1 éve
szülő
commit
01e9eee7dd

+ 4 - 1
Userland/Libraries/LibJS/Bytecode/Interpreter.cpp

@@ -1248,7 +1248,10 @@ ThrowCompletionOr<void> Call::execute_impl(Bytecode::Interpreter& interpreter) c
 
 
     TRY(throw_if_needed_for_call(interpreter, callee, call_type(), expression_string()));
     TRY(throw_if_needed_for_call(interpreter, callee, call_type(), expression_string()));
 
 
-    if (m_builtin.has_value() && m_argument_count == Bytecode::builtin_argument_count(m_builtin.value()) && interpreter.realm().get_builtin_value(m_builtin.value()) == callee) {
+    if (m_builtin.has_value()
+        && m_argument_count == Bytecode::builtin_argument_count(m_builtin.value())
+        && callee.is_object()
+        && interpreter.realm().get_builtin_value(m_builtin.value()) == &callee.as_object()) {
         interpreter.set(dst(), TRY(dispatch_builtin_call(interpreter, m_builtin.value(), { m_arguments, m_argument_count })));
         interpreter.set(dst(), TRY(dispatch_builtin_call(interpreter, m_builtin.value(), { m_arguments, m_argument_count })));
         return {};
         return {};
     }
     }

+ 4 - 4
Userland/Libraries/LibJS/Runtime/Realm.h

@@ -52,14 +52,14 @@ public:
     HostDefined* host_defined() { return m_host_defined; }
     HostDefined* host_defined() { return m_host_defined; }
     void set_host_defined(OwnPtr<HostDefined> host_defined) { m_host_defined = move(host_defined); }
     void set_host_defined(OwnPtr<HostDefined> host_defined) { m_host_defined = move(host_defined); }
 
 
-    void define_builtin(Bytecode::Builtin builtin, Value value)
+    void define_builtin(Bytecode::Builtin builtin, NonnullGCPtr<NativeFunction> value)
     {
     {
         m_builtins[to_underlying(builtin)] = value;
         m_builtins[to_underlying(builtin)] = value;
     }
     }
 
 
-    Value get_builtin_value(Bytecode::Builtin builtin)
+    NonnullGCPtr<NativeFunction> get_builtin_value(Bytecode::Builtin builtin)
     {
     {
-        return m_builtins[to_underlying(builtin)];
+        return *m_builtins[to_underlying(builtin)];
     }
     }
 
 
     static FlatPtr global_environment_offset() { return OFFSET_OF(Realm, m_global_environment); }
     static FlatPtr global_environment_offset() { return OFFSET_OF(Realm, m_global_environment); }
@@ -74,7 +74,7 @@ private:
     GCPtr<Object> m_global_object;                 // [[GlobalObject]]
     GCPtr<Object> m_global_object;                 // [[GlobalObject]]
     GCPtr<GlobalEnvironment> m_global_environment; // [[GlobalEnv]]
     GCPtr<GlobalEnvironment> m_global_environment; // [[GlobalEnv]]
     OwnPtr<HostDefined> m_host_defined;            // [[HostDefined]]
     OwnPtr<HostDefined> m_host_defined;            // [[HostDefined]]
-    AK::Array<Value, to_underlying(Bytecode::Builtin::__Count)> m_builtins;
+    AK::Array<GCPtr<NativeFunction>, to_underlying(Bytecode::Builtin::__Count)> m_builtins;
 };
 };
 
 
 }
 }