Revision: 3317
Author: [email protected]
Date: Tue Nov 17 02:28:04 2009
Log: 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.
Review URL: http://codereview.chromium.org/402008
http://code.google.com/p/v8/source/detail?r=3317

Modified:
  /branches/bleeding_edge/src/ia32/codegen-ia32.cc
  /branches/bleeding_edge/src/runtime.cc
  /branches/bleeding_edge/src/x64/codegen-x64.cc

=======================================
--- /branches/bleeding_edge/src/ia32/codegen-ia32.cc    Tue Nov 17 00:35:43  
2009
+++ /branches/bleeding_edge/src/ia32/codegen-ia32.cc    Tue Nov 17 02:28:04  
2009
@@ -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);
=======================================
--- /branches/bleeding_edge/src/runtime.cc      Wed Nov 11 07:25:51 2009
+++ /branches/bleeding_edge/src/runtime.cc      Tue Nov 17 02:28:04 2009
@@ -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();
    }
=======================================
--- /branches/bleeding_edge/src/x64/codegen-x64.cc      Tue Nov 17 00:35:43 2009
+++ /branches/bleeding_edge/src/x64/codegen-x64.cc      Tue Nov 17 02:28:04 2009
@@ -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