From fa001d1b6afc7540f09dd018291ca63f4ab00474 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Fri, 5 Jul 2013 12:57:38 +0000 Subject: [PATCH] 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 R=bmeurer@chromium.org, yangguo@chromium.org Review URL: https://codereview.chromium.org/18057004 Patch from Weiliang Lin . git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15522 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/macros.py | 1 + src/string.js | 6 ++++-- src/zone.cc | 11 ++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/macros.py b/src/macros.py index e442b44..5174d5f 100644 --- a/src/macros.py +++ b/src/macros.py @@ -145,6 +145,7 @@ const kBoundArgumentsStartIndex = 2; 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); diff --git a/src/string.js b/src/string.js index 7e18687..cb82c16 100644 --- a/src/string.js +++ b/src/string.js @@ -185,7 +185,8 @@ function StringMatch(regexp) { 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 @@ function StringReplace(search, replace) { 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)) { diff --git a/src/zone.cc b/src/zone.cc index 2a0a0e2..9ee00ed 100644 --- a/src/zone.cc +++ b/src/zone.cc @@ -92,18 +92,15 @@ void Zone::DeleteAll() { #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 -- 2.7.4