Patch by Vitaly Repeshko. Improve performance of internal fields
authorkasperl@chromium.org <kasperl@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 17 Jul 2009 09:16:23 +0000 (09:16 +0000)
committerkasperl@chromium.org <kasperl@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 17 Jul 2009 09:16:23 +0000 (09:16 +0000)
operations by adding a fast-case check for JS_OBJECT_TYPE in
JSObject::GetHeaderSize().
Review URL: http://codereview.chromium.org/155684

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2497 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/objects-inl.h

index 37c9b8b61d9544431b753b38ef0b55cbd1759702..7abc7c3eeaf075e3b7c22d1d34739ba4a974afe6 100644 (file)
@@ -1075,7 +1075,12 @@ void JSGlobalPropertyCell::set_value(Object* val, WriteBarrierMode ignored) {
 
 
 int JSObject::GetHeaderSize() {
-  switch (map()->instance_type()) {
+  InstanceType type = map()->instance_type();
+  // Check for the most common kind of JavaScript object before
+  // falling into the generic switch. This speeds up the internal
+  // field operations considerably on average.
+  if (type == JS_OBJECT_TYPE) return JSObject::kHeaderSize;
+  switch (type) {
     case JS_GLOBAL_PROXY_TYPE:
       return JSGlobalProxy::kSize;
     case JS_GLOBAL_OBJECT_TYPE:
@@ -1090,7 +1095,6 @@ int JSObject::GetHeaderSize() {
       return JSValue::kSize;
     case JS_REGEXP_TYPE:
       return JSValue::kSize;
-    case JS_OBJECT_TYPE:
     case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
       return JSObject::kHeaderSize;
     default: