Faster handling of string indexing using [] with a SMI index.
authorfschneider@chromium.org <fschneider@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 28 Dec 2009 13:01:03 +0000 (13:01 +0000)
committerfschneider@chromium.org <fschneider@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 28 Dec 2009 13:01:03 +0000 (13:01 +0000)
Instead of falling back to calling GetObjectProperty we call GetCharAt
directly if the object is a string and the key in a SMI.

Review URL: http://codereview.chromium.org/522015

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

src/runtime.cc

index 8349833..b01e201 100644 (file)
@@ -2724,7 +2724,6 @@ static Object* Runtime_GetProperty(Arguments args) {
 }
 
 
-
 // KeyedStringGetProperty is called from KeyedLoadIC::GenerateGeneric.
 static Object* Runtime_KeyedGetProperty(Arguments args) {
   NoHandleAllocation ha;
@@ -2776,6 +2775,13 @@ static Object* Runtime_KeyedGetProperty(Arguments args) {
         // If value is the hole do the general lookup.
       }
     }
+  } else if (args[0]->IsString() && args[1]->IsSmi()) {
+    // Fast case for string indexing using [] with a smi index.
+    HandleScope scope;
+    Handle<String> str = args.at<String>(0);
+    int index = Smi::cast(args[1])->value();
+    Handle<Object> result = GetCharAt(str, index);
+    return *result;
   }
 
   // Fall back to GetObjectProperty.