Reviewers: Christian Plesner Hansen, Message: hey thanks for the review!
I actually thought about using the StringBuilder, but because of the array operations to do a StringBuilder (and the fact that I do not know if the concat function is being called inside of a loop), I opted to just simply go with a concat operation and delay the overhead of the flattening until everything is done. I don't know how to attach a file here, but my benchmarks show that even in the case where there is a .concat() with like 20 arguments - probably very unlikely but would be a really good case for a stringbuilder, because of the array overhead, it's actually slower. which also tells me that StringBuilder could probably be optimized somehow :) Description: Array.join() is really slow and has array memory allocation overhead... instead concat the strings similar to str += "..."; Please review this at http://codereview.chromium.org/243053 SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/ Affected files: M src/string.js Index: src/string.js =================================================================== --- src/string.js (revision 3000) +++ src/string.js (working copy) @@ -88,11 +88,11 @@ // ECMA-262, section 15.5.4.6 function StringConcat() { var len = %_ArgumentsLength(); - var parts = new $Array(len + 1); - parts[0] = ToString(this); - for (var i = 0; i < len; i++) - parts[i + 1] = ToString(%_Arguments(i)); - return parts.join(''); + var this_string = ToString(this); + for (var i = 0; i < len; i++) { + this_string = %StringAdd(this_string, ToString(%_Arguments(i))); + } + return this_string; } // Match ES3 and Safari --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---
