Revision: 15522
Author:   [email protected]
Date:     Fri Jul  5 05:57:38 2013
Log:      Refactored code a bit to improve StringReplace performance

1. Use inline macro to mitigate the side effect emulation overhead
2. Refactor Zone::DeleteAll() to merge two loops together

[email protected], [email protected]

Review URL: https://codereview.chromium.org/18057004

Patch from Weiliang Lin <[email protected]>.
http://code.google.com/p/v8/source/detail?r=15522

Modified:
 /branches/bleeding_edge/src/macros.py
 /branches/bleeding_edge/src/string.js
 /branches/bleeding_edge/src/zone.cc

=======================================
--- /branches/bleeding_edge/src/macros.py       Mon Jun 24 06:58:52 2013
+++ /branches/bleeding_edge/src/macros.py       Fri Jul  5 05:57:38 2013
@@ -145,6 +145,7 @@
 macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg));
macro NUMBER_IS_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || ((arg == arg) && (arg != 1/0) && (arg != -1/0))); macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToInteger(ToNumber(arg))); +macro TO_INTEGER_FOR_SIDE_EFFECT(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToNumber(arg)); macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(ToNumber(arg)));
 macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : (arg >> 0));
 macro TO_UINT32(arg) = (arg >>> 0);
=======================================
--- /branches/bleeding_edge/src/string.js       Thu Jun 20 01:13:21 2013
+++ /branches/bleeding_edge/src/string.js       Fri Jul  5 05:57:38 2013
@@ -185,7 +185,8 @@
   if (IS_REGEXP(regexp)) {
     // Emulate RegExp.prototype.exec's side effect in step 5, even though
     // value is discarded.
-    ToInteger(regexp.lastIndex);
+    var lastIndex = regexp.lastIndex;
+    TO_INTEGER_FOR_SIDE_EFFECT(lastIndex);
     if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0);
     %_Log('regexp', 'regexp-match,%0S,%1r', [subject, regexp]);
     // lastMatchInfo is defined in regexp.js.
@@ -236,7 +237,8 @@
   if (IS_REGEXP(search)) {
     // Emulate RegExp.prototype.exec's side effect in step 5, even if
     // value is discarded.
-    ToInteger(search.lastIndex);
+    var lastIndex = search.lastIndex;
+    TO_INTEGER_FOR_SIDE_EFFECT(lastIndex);
     %_Log('regexp', 'regexp-replace,%0r,%1S', [search, subject]);

     if (!IS_SPEC_FUNCTION(replace)) {
=======================================
--- /branches/bleeding_edge/src/zone.cc Wed Jul  3 04:40:30 2013
+++ /branches/bleeding_edge/src/zone.cc Fri Jul  5 05:57:38 2013
@@ -92,18 +92,15 @@
 #endif

   // Find a segment with a suitable size to keep around.
-  Segment* keep = segment_head_;
-  while (keep != NULL && keep->size() > kMaximumKeptSegmentSize) {
-    keep = keep->next();
-  }
-
+  Segment* keep = NULL;
   // Traverse the chained list of segments, zapping (in debug mode)
   // and freeing every segment except the one we wish to keep.
   for (Segment* current = segment_head_; current != NULL; ) {
     Segment* next = current->next();
-    if (current == keep) {
+    if (keep == NULL && current->size() <= kMaximumKeptSegmentSize) {
       // Unlink the segment we wish to keep from the list.
-      current->clear_next();
+      keep = current;
+      keep->clear_next();
     } else {
       int size = current->size();
 #ifdef DEBUG

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to