From 9f65b1e32dda80646625557b4b6372120389dc67 Mon Sep 17 00:00:00 2001 From: "vitalyr@chromium.org" Date: Wed, 25 Aug 2010 17:50:37 +0000 Subject: [PATCH] Explicitly set expected number of properties for instances of builtin types. We used to inherit an estimate on the expected number of properties in %SetCode. It is not accurate and does not help for the types where adding custom properties is rare (String, Date, etc.). Review URL: http://codereview.chromium.org/3191026 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5348 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/runtime.cc | 12 +++++++++++- src/runtime.h | 1 + src/v8natives.js | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/runtime.cc b/src/runtime.cc index 1122d33..f908036 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -1701,7 +1701,6 @@ static Object* Runtime_SetCode(Arguments args) { RUNTIME_ASSERT(code->IsJSFunction()); Handle fun = Handle::cast(code); Handle shared(fun->shared()); - SetExpectedNofProperties(target, shared->expected_nof_properties()); if (!EnsureCompiled(shared, KEEP_EXCEPTION)) { return Failure::Exception(); @@ -1746,6 +1745,17 @@ static Object* Runtime_SetCode(Arguments args) { } +static Object* Runtime_SetExpectedNumberOfProperties(Arguments args) { + HandleScope scope; + ASSERT(args.length() == 2); + CONVERT_ARG_CHECKED(JSFunction, function, 0); + CONVERT_SMI_CHECKED(num, args[1]); + RUNTIME_ASSERT(num >= 0); + SetExpectedNofProperties(function, num); + return Heap::undefined_value(); +} + + static Object* CharFromCode(Object* char_code) { uint32_t code; if (char_code->ToArrayIndex(&code)) { diff --git a/src/runtime.h b/src/runtime.h index 1d2c4f2..71d95cf 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -201,6 +201,7 @@ namespace internal { \ F(ClassOf, 1, 1) \ F(SetCode, 2, 1) \ + F(SetExpectedNumberOfProperties, 2, 1) \ \ F(CreateApiFunction, 1, 1) \ F(IsTemplate, 1, 1) \ diff --git a/src/v8natives.js b/src/v8natives.js index 85540e8..93e4f8b 100644 --- a/src/v8natives.js +++ b/src/v8natives.js @@ -836,6 +836,7 @@ function ObjectIsExtensible(obj) { } }); +%SetExpectedNumberOfProperties($Object, 4); // ---------------------------------------------------------------------------- -- 2.7.4