Commit 22fedb0e authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[torque] avoid GetStringData dispatch repetition

Change-Id: I31d2a19153fa17e6e78d3da93352da886addf089
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2581960
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71832}
parent a14107f7
......@@ -352,9 +352,6 @@ transitioning macro StoreLastIndex(implicit context: Context)(
}
}
extern builtin
StringIndexOf(implicit context: Context)(String, String, Smi): Smi;
extern macro RegExpBuiltinsAssembler::AdvanceStringIndex(
String, Number, bool, constexpr bool): Number;
extern macro
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
namespace string {
// TODO(tebbi): This could be replaced with a fast C-call to
// CompareCharsUnsigned.
macro IsSubstringAt<A: type, B: type>(
......@@ -23,27 +21,20 @@ macro IsSubstringAt<A: type, B: type>(
VerifiedUnreachable();
}
struct IsSubstringAtFunctor {
start: intptr;
}
// Ideally, this would be a method of IsSubstringAtFunctor, but currently
// methods don't support templates.
macro Call<A: type, B: type>(
self: IsSubstringAtFunctor, string: ConstSlice<A>,
searchStr: ConstSlice<B>): bool {
return IsSubstringAt(string, searchStr, self.start);
}
macro IsSubstringAt(string: String, searchStr: String, start: intptr): bool {
// TODO(tebbi): Avoid repeating this verbose pattern.
try {
GetStringData(string) otherwise FirstOneByte, FirstTwoByte;
} label FirstOneByte(string: ConstSlice<char8>) {
try {
GetStringData(searchStr) otherwise SecondOneByte, SecondTwoByte;
} label SecondOneByte(searchStr: ConstSlice<char8>) {
return IsSubstringAt(string, searchStr, start);
} label SecondTwoByte(searchStr: ConstSlice<char16>) {
return IsSubstringAt(string, searchStr, start);
}
} label FirstTwoByte(string: ConstSlice<char16>) {
try {
GetStringData(searchStr) otherwise SecondOneByte, SecondTwoByte;
} label SecondOneByte(searchStr: ConstSlice<char8>) {
return IsSubstringAt(string, searchStr, start);
} label SecondTwoByte(searchStr: ConstSlice<char16>) {
return IsSubstringAt(string, searchStr, start);
}
}
return TwoStringsToSlices<bool>(
string, searchStr, IsSubstringAtFunctor{start: start});
}
// https://tc39.github.io/ecma262/#sec-string.prototype.endswith
......@@ -91,4 +82,3 @@ transitioning javascript builtin StringPrototypeEndsWith(
// 13. Otherwise, return false.
return Convert<Boolean>(IsSubstringAt(string, searchStr, start));
}
}
......@@ -4,7 +4,6 @@
#include 'src/builtins/builtins-string-gen.h'
namespace string {
extern macro ReplaceSymbolConstant(): Symbol;
extern macro StringBuiltinsAssembler::GetSubstitution(
......@@ -25,6 +24,17 @@ macro AbstractStringIndexOf<A: type, B: type>(
return -1;
}
struct AbstractStringIndexOfFunctor {
fromIndex: Smi;
}
// Ideally, this would be a method of AbstractStringIndexOfFunctor, but
// currently methods don't support templates.
macro Call<A: type, B: type>(
self: AbstractStringIndexOfFunctor, string: ConstSlice<A>,
searchStr: ConstSlice<B>): Smi {
return AbstractStringIndexOf(string, searchStr, self.fromIndex);
}
macro AbstractStringIndexOf(implicit context: Context)(
string: String, searchString: String, fromIndex: Smi): Smi {
// Special case the empty string.
......@@ -41,25 +51,8 @@ macro AbstractStringIndexOf(implicit context: Context)(
return -1;
}
try {
GetStringData(string) otherwise FirstOneByte, FirstTwoByte;
} label FirstOneByte(stringData: ConstSlice<char8>) {
try {
GetStringData(searchString) otherwise SecondOneByte, SecondTwoByte;
} label SecondOneByte(searchStringData: ConstSlice<char8>) {
return AbstractStringIndexOf(stringData, searchStringData, fromIndex);
} label SecondTwoByte(searchStringData: ConstSlice<char16>) {
return AbstractStringIndexOf(stringData, searchStringData, fromIndex);
}
} label FirstTwoByte(stringData: ConstSlice<char16>) {
try {
GetStringData(searchString) otherwise SecondOneByte, SecondTwoByte;
} label SecondOneByte(searchStringData: ConstSlice<char8>) {
return AbstractStringIndexOf(stringData, searchStringData, fromIndex);
} label SecondTwoByte(searchStringData: ConstSlice<char16>) {
return AbstractStringIndexOf(stringData, searchStringData, fromIndex);
}
}
return TwoStringsToSlices<Smi>(
string, searchString, AbstractStringIndexOfFunctor{fromIndex: fromIndex});
}
transitioning macro
......@@ -210,4 +203,3 @@ transitioning javascript builtin StringPrototypeReplaceAll(
// 16. Return result.
return result;
}
}
......@@ -139,7 +139,7 @@ transitioning macro StringTrim(implicit context: Context)(
const receiverString: String = ToThisString(receiver, methodName);
try {
GetStringData(receiverString) otherwise OneByte, TwoByte;
StringToSlice(receiverString) otherwise OneByte, TwoByte;
} label OneByte(slice: ConstSlice<char8>) {
return StringTrimBody(receiverString, slice, variant);
} label TwoByte(slice: ConstSlice<char16>) {
......
......@@ -242,7 +242,7 @@ macro Flatten(cons: ConsString): String {
}
// Get a slice to the string data, flatten only if unavoidable for this.
macro GetStringData(string: String): never labels OneByte(ConstSlice<char8>),
macro StringToSlice(string: String): never labels OneByte(ConstSlice<char8>),
TwoByte(ConstSlice<char16>) {
let string = string;
let offset: intptr = 0;
......@@ -282,3 +282,27 @@ macro GetStringData(string: String): never labels OneByte(ConstSlice<char8>),
}
VerifiedUnreachable();
}
// Dispatch on the slice type of two different strings.
macro TwoStringsToSlices<Result: type, Functor: type>(
s1: String, s2: String, f: Functor): Result {
try {
StringToSlice(s1) otherwise FirstOneByte, FirstTwoByte;
} label FirstOneByte(s1Slice: ConstSlice<char8>) {
try {
StringToSlice(s2) otherwise SecondOneByte, SecondTwoByte;
} label SecondOneByte(s2Slice: ConstSlice<char8>) {
return Call(f, s1Slice, s2Slice);
} label SecondTwoByte(s2Slice: ConstSlice<char16>) {
return Call(f, s1Slice, s2Slice);
}
} label FirstTwoByte(s1Slice: ConstSlice<char16>) {
try {
StringToSlice(s2) otherwise SecondOneByte, SecondTwoByte;
} label SecondOneByte(s2Slice: ConstSlice<char8>) {
return Call(f, s1Slice, s2Slice);
} label SecondTwoByte(s2Slice: ConstSlice<char16>) {
return Call(f, s1Slice, s2Slice);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment