Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Unified Diff: src/string.js

Issue 10996065: Improves performance for calls from Crankshaft code to certain string and... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/regexp.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/string.js
===================================================================
--- src/string.js (revision 12582)
+++ src/string.js (working copy)
@@ -199,6 +199,37 @@
}
+function StringMatchNoResult(regexp) {
+ if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
+ throw MakeTypeError("called_on_null_or_undefined",
+ ["String.prototype.match"]);
+ }
+ var subject = TO_STRING_INLINE(this);
+ if (!IS_REGEXP(regexp))
+ regexp = new $RegExp(regexp);
+ if (!regexp.global) {
+ %_CallFunction(regexp, subject, RegExpExecNoResult);
+ } else {
+ regexp.lastIndex = 0;
+ var previousLastIndex = 0;
+ var lastMatch = true;
+ while (lastMatch) {
+ var result = %_CallFunction(regexp, subject, RegExpExecNoResult);
+ if (result == null)
+ lastMatch = false;
+ else {
+ var thisIndex = regexp.lastIndex;
+ if (thisIndex == previousLastIndex) {
+ regexp.lastIndex += 1;
+ previousLastIndex += 1;
+ } else {
+ previousLastIndex = thisIndex;
+ }
+ }
+ }
+ }
+}
+
// SubString is an internal function that returns the sub string of 'string'.
// If resulting string is of length 1, we use the one character cache
// otherwise we call the runtime system.
@@ -294,6 +325,28 @@
}
+function StringReplaceNoResult(search, replace) {
+ if (IS_FUNCTION(replace)) {
+ // The function may have side effects, so we punt to the real method
+ return %_CallFunction(this, search, replace, StringReplace);
+ }
+
+ if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
+ throw MakeTypeError("called_on_null_or_undefined",
+ ["String.prototype.replace"]);
+ }
+
+ var subject = TO_STRING_INLINE(this);
+
+ if (IS_REGEXP(search)) {
+ %_CallFunction(subject, search, StringMatchNoResult);
+ } else {
+ TO_STRING_INLINE(search);
+ }
+ TO_STRING_INLINE(replace);
+}
+
+
// Expand the $-expressions in the string and return a new string with
// the result.
function ExpandReplacement(string, subject, matchInfo, result) {
@@ -654,6 +707,29 @@
}
+function StringSplitNoResult(separator, limit) {
+ if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
+ throw MakeTypeError("called_on_null_or_undefined",
+ ["String.prototype.split"]);
+ }
+ TO_STRING_INLINE(this);
+ limit = (IS_UNDEFINED(limit)) ? 0xffffffff : TO_UINT32(limit);
+ if (limit === 0) return;
+
+ // ECMA-262 says that if separator is undefined, the result should
+ // be an array of size 1 containing the entire string. SpiderMonkey
+ // and KJS have this behavior only when no separator is given. If
+ // undefined is explicitly given, they convert it to a string and
+ // use that. We do as SpiderMonkey and KJS.
+ if (%_ArgumentsLength() === 0) {
+ return;
+ }
+
+ if (!IS_REGEXP(separator))
+ TO_STRING_INLINE(separator);
+}
+
+
// ECMA-262 section 15.5.4.15
function StringSubstring(start, end) {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
« no previous file with comments | « src/regexp.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698