v8/test/mjsunit/compiler/string-startswith.js
Ujjwal Sharma acadb20271 [turbofan] add fast path for String.p.startsWith
Add a fast path for String.p.startsWith(str) when length of str is 1.

Bug: v8:8400
Change-Id: I65e657549902dc3ad064a213d815dd098ce6455f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1491872
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60091}
2019-03-07 12:37:39 +00:00

22 lines
651 B
JavaScript

// Copyright 2019 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.
// Flags: --allow-natives-syntax --opt
(function() {
function foo(string) { return string.startsWith('a'); }
%PrepareFunctionForOptimization(foo);
assertEquals(false, foo(''));
assertEquals(true, foo('a'));
assertEquals(false, foo('ba'));
assertEquals(true, foo('abc'));
%OptimizeFunctionOnNextCall(foo);
assertEquals(false, foo(''));
assertEquals(true, foo('a'));
assertEquals(false, foo('ba'));
assertEquals(true, foo('abc'));
assertOptimized(foo);
})();