Commit fa001d1b authored by yangguo@chromium.org's avatar yangguo@chromium.org

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 <weiliang.lin2@gmail.com>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15522 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a3b6452d
...@@ -145,6 +145,7 @@ const kBoundArgumentsStartIndex = 2; ...@@ -145,6 +145,7 @@ const kBoundArgumentsStartIndex = 2;
macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg)); 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 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(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_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_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : (arg >> 0));
macro TO_UINT32(arg) = (arg >>> 0); macro TO_UINT32(arg) = (arg >>> 0);
......
...@@ -185,7 +185,8 @@ function StringMatch(regexp) { ...@@ -185,7 +185,8 @@ function StringMatch(regexp) {
if (IS_REGEXP(regexp)) { if (IS_REGEXP(regexp)) {
// Emulate RegExp.prototype.exec's side effect in step 5, even though // Emulate RegExp.prototype.exec's side effect in step 5, even though
// value is discarded. // value is discarded.
ToInteger(regexp.lastIndex); var lastIndex = regexp.lastIndex;
TO_INTEGER_FOR_SIDE_EFFECT(lastIndex);
if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0); if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0);
%_Log('regexp', 'regexp-match,%0S,%1r', [subject, regexp]); %_Log('regexp', 'regexp-match,%0S,%1r', [subject, regexp]);
// lastMatchInfo is defined in regexp.js. // lastMatchInfo is defined in regexp.js.
...@@ -236,7 +237,8 @@ function StringReplace(search, replace) { ...@@ -236,7 +237,8 @@ function StringReplace(search, replace) {
if (IS_REGEXP(search)) { if (IS_REGEXP(search)) {
// Emulate RegExp.prototype.exec's side effect in step 5, even if // Emulate RegExp.prototype.exec's side effect in step 5, even if
// value is discarded. // value is discarded.
ToInteger(search.lastIndex); var lastIndex = search.lastIndex;
TO_INTEGER_FOR_SIDE_EFFECT(lastIndex);
%_Log('regexp', 'regexp-replace,%0r,%1S', [search, subject]); %_Log('regexp', 'regexp-replace,%0r,%1S', [search, subject]);
if (!IS_SPEC_FUNCTION(replace)) { if (!IS_SPEC_FUNCTION(replace)) {
......
...@@ -92,18 +92,15 @@ void Zone::DeleteAll() { ...@@ -92,18 +92,15 @@ void Zone::DeleteAll() {
#endif #endif
// Find a segment with a suitable size to keep around. // Find a segment with a suitable size to keep around.
Segment* keep = segment_head_; Segment* keep = NULL;
while (keep != NULL && keep->size() > kMaximumKeptSegmentSize) {
keep = keep->next();
}
// Traverse the chained list of segments, zapping (in debug mode) // Traverse the chained list of segments, zapping (in debug mode)
// and freeing every segment except the one we wish to keep. // and freeing every segment except the one we wish to keep.
for (Segment* current = segment_head_; current != NULL; ) { for (Segment* current = segment_head_; current != NULL; ) {
Segment* next = current->next(); Segment* next = current->next();
if (current == keep) { if (keep == NULL && current->size() <= kMaximumKeptSegmentSize) {
// Unlink the segment we wish to keep from the list. // Unlink the segment we wish to keep from the list.
current->clear_next(); keep = current;
keep->clear_next();
} else { } else {
int size = current->size(); int size = current->size();
#ifdef DEBUG #ifdef DEBUG
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment