v8/test/mjsunit/maglev/string-at.js
Victor Gomes aebad779e9 [maglev] Add fast path for strings in element access
Currently it falls back to runtime for externalized strings.

Bug: v8:7700
Change-Id: I9bc09969915e437af5fcf563ba74a6edd9280779
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3956975
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83745}
2022-10-17 14:45:35 +00:00

69 lines
1.5 KiB
JavaScript

// Copyright 2022 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 --maglev
// Sequential string (1 byte string).
(function() {
let s = "my string";
function foo() {
return s[3];
}
%PrepareFunctionForOptimization(foo);
assertEquals("s", foo());
%OptimizeMaglevOnNextCall(foo);
assertEquals("s", foo());
})();
// Sequential string (2 byte string).
(function() {
let s = "my ⚡tring";
function foo() {
return s[3];
}
%PrepareFunctionForOptimization(foo);
assertEquals("⚡", foo());
%OptimizeMaglevOnNextCall(foo);
assertEquals("⚡", foo());
})();
// Cons string.
(function() {
let s = "my"
s += " ";
s += "string";
function foo() {
return s[3];
}
%PrepareFunctionForOptimization(foo);
assertEquals("s", foo());
%OptimizeMaglevOnNextCall(foo);
assertEquals("s", foo());
})();
// Thin string.
(function() {
let s = %ConstructThinString("my string is thin!");
function foo() {
return s[3];
}
%PrepareFunctionForOptimization(foo);
assertEquals("s", foo());
%OptimizeMaglevOnNextCall(foo);
assertEquals("s", foo());
})();
// Sliced string.
(function() {
let main_string = "The quick brown fox jumps over the lazy dog.";
let s = main_string.slice(4, 19);
function foo() {
return s[0];
}
%PrepareFunctionForOptimization(foo);
assertEquals("q", foo());
%OptimizeMaglevOnNextCall(foo);
assertEquals("q", foo());
})();