mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:27:35 +00:00
LibJS: Cache commonly used FlyStrings in the VM
Roughly 7% of test-js runtime was spent creating FlyStrings from string literals. This patch frontloads that work and caches all the commonly used names in LibJS on a CommonPropertyNames struct that hangs off VM.
This commit is contained in:
parent
9f6c5f68b6
commit
7b863330dc
45 changed files with 651 additions and 392 deletions
|
@ -30,34 +30,36 @@
|
|||
#include <LibJS/Runtime/NumberObject.h>
|
||||
#include <math.h>
|
||||
|
||||
#define EPSILON pow(2, -52)
|
||||
#define MAX_SAFE_INTEGER pow(2, 53) - 1
|
||||
#define MIN_SAFE_INTEGER -(pow(2, 53) - 1)
|
||||
// FIXME: constexpr these?
|
||||
#define EPSILON_VALUE pow(2, -52)
|
||||
#define MAX_SAFE_INTEGER_VALUE pow(2, 53) - 1
|
||||
#define MIN_SAFE_INTEGER_VALUE -(pow(2, 53) - 1)
|
||||
|
||||
namespace JS {
|
||||
|
||||
NumberConstructor::NumberConstructor(GlobalObject& global_object)
|
||||
: NativeFunction("Number", *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.Number, *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
void NumberConstructor::initialize(GlobalObject& global_object)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
NativeFunction::initialize(global_object);
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function("isFinite", is_finite, 1, attr);
|
||||
define_native_function("isInteger", is_integer, 1, attr);
|
||||
define_native_function("isNaN", is_nan, 1, attr);
|
||||
define_native_function("isSafeInteger", is_safe_integer, 1, attr);
|
||||
define_property("parseFloat", global_object.get("parseFloat"));
|
||||
define_property("prototype", global_object.number_prototype(), 0);
|
||||
define_property("length", Value(1), Attribute::Configurable);
|
||||
define_property("EPSILON", Value(EPSILON), 0);
|
||||
define_property("MAX_SAFE_INTEGER", Value(MAX_SAFE_INTEGER), 0);
|
||||
define_property("MIN_SAFE_INTEGER", Value(MIN_SAFE_INTEGER), 0);
|
||||
define_property("NEGATIVE_INFINITY", js_negative_infinity(), 0);
|
||||
define_property("POSITIVE_INFINITY", js_infinity(), 0);
|
||||
define_property("NaN", js_nan(), 0);
|
||||
define_native_function(vm.names.isFinite, is_finite, 1, attr);
|
||||
define_native_function(vm.names.isInteger, is_integer, 1, attr);
|
||||
define_native_function(vm.names.isNaN, is_nan, 1, attr);
|
||||
define_native_function(vm.names.isSafeInteger, is_safe_integer, 1, attr);
|
||||
define_property(vm.names.parseFloat, global_object.get(vm.names.parseFloat));
|
||||
define_property(vm.names.prototype, global_object.number_prototype(), 0);
|
||||
define_property(vm.names.length, Value(1), Attribute::Configurable);
|
||||
define_property(vm.names.EPSILON, Value(EPSILON_VALUE), 0);
|
||||
define_property(vm.names.MAX_SAFE_INTEGER, Value(MAX_SAFE_INTEGER_VALUE), 0);
|
||||
define_property(vm.names.MIN_SAFE_INTEGER, Value(MIN_SAFE_INTEGER_VALUE), 0);
|
||||
define_property(vm.names.NEGATIVE_INFINITY, js_negative_infinity(), 0);
|
||||
define_property(vm.names.POSITIVE_INFINITY, js_infinity(), 0);
|
||||
define_property(vm.names.NaN, js_nan(), 0);
|
||||
}
|
||||
|
||||
NumberConstructor::~NumberConstructor()
|
||||
|
@ -102,7 +104,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberConstructor::is_safe_integer)
|
|||
if (!vm.argument(0).is_number())
|
||||
return Value(false);
|
||||
auto value = vm.argument(0).as_double();
|
||||
return Value((int64_t)value == value && value >= MIN_SAFE_INTEGER && value <= MAX_SAFE_INTEGER);
|
||||
return Value((int64_t)value == value && value >= MIN_SAFE_INTEGER_VALUE && value <= MAX_SAFE_INTEGER_VALUE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue