mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-12 23:36:28 -05:00
Use a bitmask to avoid unnecessary calls to contains in indexOfAnyCharCode.
This commit is contained in:
@@ -230,8 +230,14 @@ export function contains<T>(array: readonly T[] | undefined, value: T, equalityC
|
||||
|
||||
/** @internal */
|
||||
export function indexOfAnyCharCode(text: string, charCodes: readonly number[], start?: number): number {
|
||||
let bitMask = 0;
|
||||
for (let i = 0; i < charCodes.length; i++) {
|
||||
bitMask |= charCodes[i];
|
||||
}
|
||||
|
||||
for (let i = start ?? 0; i < text.length; i++) {
|
||||
if (contains(charCodes, text.charCodeAt(i))) {
|
||||
const current = text.charCodeAt(i);
|
||||
if ((current & bitMask) === current && contains(charCodes, current)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user