Explicitly set expected number of properties for instances of builtin types.
authorvitalyr@chromium.org <vitalyr@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 25 Aug 2010 17:50:37 +0000 (17:50 +0000)
committervitalyr@chromium.org <vitalyr@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 25 Aug 2010 17:50:37 +0000 (17:50 +0000)
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
src/runtime.h
src/v8natives.js

index 1122d33..f908036 100644 (file)
@@ -1701,7 +1701,6 @@ static Object* Runtime_SetCode(Arguments args) {
     RUNTIME_ASSERT(code->IsJSFunction());
     Handle<JSFunction> fun = Handle<JSFunction>::cast(code);
     Handle<SharedFunctionInfo> 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)) {
index 1d2c4f2..71d95cf 100644 (file)
@@ -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) \
index 85540e8..93e4f8b 100644 (file)
@@ -836,6 +836,7 @@ function ObjectIsExtensible(obj) {
   }
 });
 
+%SetExpectedNumberOfProperties($Object, 4);
 
 // ----------------------------------------------------------------------------