Reviewers: Lasse Reichstein,

Description:
Speed up charCodeAt on very large cons strings, by insisting on
flattening the strings and not trying too hard to traverse a big
cons tree from generated code.

Please review this at http://codereview.chromium.org/402008

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
   M     src/ia32/codegen-ia32.cc
   M     src/runtime.cc
   M     src/x64/codegen-x64.cc


Index: src/ia32/codegen-ia32.cc
===================================================================
--- src/ia32/codegen-ia32.cc    (revision 3315)
+++ src/ia32/codegen-ia32.cc    (working copy)
@@ -4831,6 +4831,12 @@
    __ j(not_equal, &slow_case);

    // ConsString.
+  // Check that the right hand side is the empty string (ie if this is  
really a
+  // flat string in a cons string).  If that is not the case we would  
rather go
+  // to the runtime system now, to flatten the string.
+  __ mov(temp.reg(), FieldOperand(object.reg(),  
ConsString::kSecondOffset));
+  __ cmp(Operand(temp.reg()),  
Immediate(Handle<String>(Heap::empty_string())));
+  __ j(not_equal, &slow_case);
    // Get the first of the two strings.
    __ mov(object.reg(), FieldOperand(object.reg(),  
ConsString::kFirstOffset));
    __ jmp(&try_again_with_new_string);
Index: src/runtime.cc
===================================================================
--- src/runtime.cc      (revision 3315)
+++ src/runtime.cc      (working copy)
@@ -1274,7 +1274,9 @@
    // Flatten the string.  If someone wants to get a char at an index
    // in a cons string, it is likely that more indices will be
    // accessed.
-  subject->TryFlattenIfNotFlat();
+  Object* flat = subject->TryFlatten();
+  if (flat->IsFailure()) return flat;
+  subject = String::cast(flat);
    if (i >= static_cast<uint32_t>(subject->length())) {
      return Heap::nan_value();
    }
Index: src/x64/codegen-x64.cc
===================================================================
--- src/x64/codegen-x64.cc      (revision 3315)
+++ src/x64/codegen-x64.cc      (working copy)
@@ -3778,6 +3778,12 @@
    __ j(not_equal, &slow_case);

    // ConsString.
+  // Check that the right hand side is the empty string (ie if this is  
really a
+  // flat string in a cons string).  If that is not the case we would  
rather go
+  // to the runtime system now, to flatten the string.
+  __ movq(temp.reg(), FieldOperand(object.reg(),  
ConsString::kSecondOffset));
+  __ CompareRoot(temp.reg(), Heap::kEmptyStringRootIndex);
+  __ j(not_equal, &slow_case);
    // Get the first of the two strings.
    __ movq(object.reg(), FieldOperand(object.reg(),  
ConsString::kFirstOffset));
    __ jmp(&try_again_with_new_string);



--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to