diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2010-11-16 19:13:52 -0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-11-16 19:14:14 -0800 |
commit | 03fa258df7d9e642c3ccac82d27c9c8167681cce (patch) | |
tree | 09dcbd2f391b2e81c0f50c9e2f37afd94fc1479f /deps/v8/src/string.js | |
parent | cea3a95f9fe6faaa504542d4f03349739d08a0f3 (diff) | |
download | node-new-03fa258df7d9e642c3ccac82d27c9c8167681cce.tar.gz |
Revert "Upgrade V8 to 2.5.6"
This reverts commit 564a48643bd3edc6da845e458277a54c8068d0e2.
Breaks cygwin
Diffstat (limited to 'deps/v8/src/string.js')
-rw-r--r-- | deps/v8/src/string.js | 82 |
1 files changed, 76 insertions, 6 deletions
diff --git a/deps/v8/src/string.js b/deps/v8/src/string.js index d82ce05237..d97f632b88 100644 --- a/deps/v8/src/string.js +++ b/deps/v8/src/string.js @@ -144,6 +144,16 @@ function StringLastIndexOf(searchString /* position */) { // length == 1 } +function CloneDenseArray(array) { + if (array === null) return null; + var clone = new $Array(array.length); + for (var i = 0; i < array.length; i++) { + clone[i] = array[i]; + } + return clone; +} + + // ECMA-262 section 15.5.4.9 // // This function is implementation specific. For now, we do not @@ -162,12 +172,33 @@ function StringMatch(regexp) { var subject = TO_STRING_INLINE(this); if (IS_REGEXP(regexp)) { if (!regexp.global) return regexp.exec(subject); + + var cache = regExpCache; + var saveAnswer = false; + + if (%_ObjectEquals(cache.type, 'match') && + %_IsRegExpEquivalent(cache.regExp, regexp) && + %_ObjectEquals(cache.subject, subject)) { + if (cache.answerSaved) { + return CloneDenseArray(cache.answer); + } else { + saveAnswer = true; + } + } %_Log('regexp', 'regexp-match,%0S,%1r', [subject, regexp]); // lastMatchInfo is defined in regexp.js. - return %StringMatch(subject, regexp, lastMatchInfo); + var result = %StringMatch(subject, regexp, lastMatchInfo); + cache.type = 'match'; + cache.regExp = regexp; + cache.subject = subject; + if (saveAnswer) cache.answer = CloneDenseArray(result); + cache.answerSaved = saveAnswer; + return result; } // Non-regexp argument. regexp = new $RegExp(regexp); + // Don't check regexp exec cache, since the regexp is new. + // TODO(lrn): Change this if we start caching regexps here. return RegExpExecNoTests(regexp, subject, 0); } @@ -200,6 +231,7 @@ function StringReplace(search, replace) { if (IS_REGEXP(search)) { %_Log('regexp', 'regexp-replace,%0r,%1S', [search, subject]); if (IS_FUNCTION(replace)) { + regExpCache.type = 'none'; if (search.global) { return StringReplaceGlobalRegExpWithFunction(subject, search, replace); } else { @@ -241,10 +273,24 @@ function StringReplace(search, replace) { // Helper function for regular expressions in String.prototype.replace. function StringReplaceRegExp(subject, regexp, replace) { - return %StringReplaceRegExpWithString(subject, - regexp, - TO_STRING_INLINE(replace), - lastMatchInfo); + var cache = regExpCache; + if (%_ObjectEquals(cache.type, 'replace') && + %_IsRegExpEquivalent(cache.regExp, regexp) && + %_ObjectEquals(cache.replaceString, replace) && + %_ObjectEquals(cache.subject, subject)) { + return cache.answer; + } + replace = TO_STRING_INLINE(replace); + var answer = %StringReplaceRegExpWithString(subject, + regexp, + replace, + lastMatchInfo); + cache.subject = subject; + cache.regExp = regexp; + cache.replaceString = replace; + cache.answer = answer; + cache.type = 'replace'; + return answer; } @@ -559,12 +605,34 @@ function StringSplit(separator, limit) { return result; } + var cache = regExpCache; + var saveAnswer = false; + + if (%_ObjectEquals(cache.type, 'split') && + %_IsRegExpEquivalent(cache.regExp, separator) && + %_ObjectEquals(cache.subject, subject) && + %_ObjectEquals(cache.splitLimit, limit)) { + if (cache.answerSaved) { + return CloneDenseArray(cache.answer); + } else { + saveAnswer = true; + } + } + + cache.type = 'split'; + cache.regExp = separator; + cache.subject = subject; + cache.splitLimit = limit; + %_Log('regexp', 'regexp-split,%0S,%1r', [subject, separator]); if (length === 0) { - if (DoRegExpExec(separator, subject, 0, 0) != null) { + cache.answerSaved = true; + if (splitMatch(separator, subject, 0, 0) != null) { + cache.answer = []; return []; } + cache.answer = [subject]; return [subject]; } @@ -612,6 +680,8 @@ function StringSplit(separator, limit) { startIndex = currentIndex = endIndex; } + if (saveAnswer) cache.answer = CloneDenseArray(result); + cache.answerSaved = saveAnswer; return result; } |