Added %FlattenString and use it to speed up a regression test.

Flattening strings is relatively costly and by doing it after every duplication
we avoid combinatorial explosion.

Note that flattening could have been done by e.g. using a regular expression,
too, but this is just another implementation detail and %FlattenString seems
general enough to be useful in other tests, too.

Review URL: https://codereview.chromium.org/11828014

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13337 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
svenpanne@chromium.org 2013-01-09 09:32:12 +00:00
parent 8e7f419fe2
commit 0aacbf9619
3 changed files with 13 additions and 1 deletions

View File

@ -13242,6 +13242,15 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_Abort) {
}
RUNTIME_FUNCTION(MaybeObject*, Runtime_FlattenString) {
HandleScope scope(isolate);
ASSERT(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(String, str, 0);
FlattenString(str);
return isolate->heap()->undefined_value();
}
RUNTIME_FUNCTION(MaybeObject*, Runtime_GetFromCache) {
// This is only called from codegen, so checks might be more lax.
CONVERT_ARG_CHECKED(JSFunctionResultCache, cache, 0);

View File

@ -104,6 +104,7 @@ namespace internal {
F(StoreArrayLiteralElement, 5, 1) \
F(DebugCallbackSupportsStepping, 1, 1) \
F(DebugPrepareStepInIfStepping, 1, 1) \
F(FlattenString, 1, 1) \
\
/* Array join support */ \
F(PushIfAbsent, 2, 1) \

View File

@ -25,9 +25,11 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
var str = "a";
for (var i = 0; i < 28; i++) {
str += str;
%FlattenString(str); // Evil performance hack
}
JSON.stringify(str);