f76dfee9df
This is a change from ES5 to ES6: When reversing an array, first it is checked whether the element exists, before the element is looked up. The order in ES6 is [[HasElement]] lower [[Get]] lower (if present) [[HasElement]] upper [[Get]] upper (if present) In ES5, on the other hand, the order was [[Get]] lower [[Get]] upper [[HasElement]] lower [[HasElement]] upper To mitigate the performance impact, this patch implements a new, third copy of reversing arrays if %_HasPackedElements. This allows us to skip all membership tests, and a quick and dirty benchmark shows that the new version is faster: Over 4 runs, the slowest for the new version: d8> var start = Date.now(); for (var i = 0; i < 100000000; i++) [1, 2, 3, 4, 5].reverse(); Date.now() - start 4658 Over 3 runs, the fastest for the old version: d8> var start = Date.now(); for (var i = 0; i < 100000000; i++) [1, 2, 3, 4, 5].reverse(); Date.now() - start 5176 BUG=v8:4223 R=adamk LOG=Y Review URL: https://codereview.chromium.org/1238593003 Cr-Commit-Position: refs/heads/master@{#29716}
11 lines
465 B
JavaScript
11 lines
465 B
JavaScript
// Copyright 2015 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// ES6 specifically says that elements should be checked with [[HasElement]] before
|
|
// [[Get]]. This is observable in case a getter deletes elements. ES5 put the
|
|
// [[HasElement]] after the [[Get]].
|
|
|
|
assertTrue(1 in Array.prototype.reverse.call(
|
|
{length:2, get 0(){delete this[0];}, 1: "b"}))
|