mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
perf: replace String and Array indexOf method calls with includes method call (#55482)
This commit is contained in:
@@ -4093,7 +4093,7 @@ export class ProjectService {
|
||||
for (const type of rule.types) {
|
||||
// Best-effort de-duping here - doesn't need to be unduplicated but
|
||||
// we don't want the list to become a 400-element array of just 'kendo'
|
||||
if (typeAcqInclude.indexOf(type) < 0) {
|
||||
if (!typeAcqInclude.includes(type)) {
|
||||
typeAcqInclude.push(type);
|
||||
}
|
||||
}
|
||||
@@ -4118,7 +4118,7 @@ export class ProjectService {
|
||||
}).join("");
|
||||
});
|
||||
|
||||
if (excludeRules.indexOf(processedRule) === -1) {
|
||||
if (!excludeRules.includes(processedRule)) {
|
||||
excludeRules.push(processedRule);
|
||||
}
|
||||
}
|
||||
@@ -4126,7 +4126,7 @@ export class ProjectService {
|
||||
else {
|
||||
// If not rules listed, add the default rule to exclude the matched file
|
||||
const escaped = ProjectService.escapeFilenameForRegex(root);
|
||||
if (excludeRules.indexOf(escaped) < 0) {
|
||||
if (!excludeRules.includes(escaped)) {
|
||||
excludeRules.push(escaped);
|
||||
}
|
||||
}
|
||||
@@ -4155,7 +4155,7 @@ export class ProjectService {
|
||||
exclude = true;
|
||||
// ... but *include* it in the list of types to acquire
|
||||
// Same best-effort dedupe as above
|
||||
if (typeAcqInclude.indexOf(typeName) < 0) {
|
||||
if (!typeAcqInclude.includes(typeName)) {
|
||||
typeAcqInclude.push(typeName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1503,7 +1503,7 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
|
||||
|
||||
protected removeExistingTypings(include: string[]): string[] {
|
||||
const existing = getAutomaticTypeDirectiveNames(this.getCompilerOptions(), this.directoryStructureHost);
|
||||
return include.filter(i => existing.indexOf(i) < 0);
|
||||
return include.filter(i => !existing.includes(i));
|
||||
}
|
||||
|
||||
private updateGraphWorker() {
|
||||
|
||||
@@ -31,7 +31,6 @@ import {
|
||||
some,
|
||||
SourceFile,
|
||||
SourceFileLike,
|
||||
stringContains,
|
||||
TextSpan,
|
||||
unorderedRemoveItem,
|
||||
} from "./_namespaces/ts";
|
||||
@@ -339,9 +338,9 @@ export class TextStorage {
|
||||
|
||||
export function isDynamicFileName(fileName: NormalizedPath) {
|
||||
return fileName[0] === "^" ||
|
||||
((stringContains(fileName, "walkThroughSnippet:/") || stringContains(fileName, "untitled:/")) &&
|
||||
((fileName.includes("walkThroughSnippet:/") || fileName.includes("untitled:/")) &&
|
||||
getBaseFileName(fileName)[0] === "^") ||
|
||||
(stringContains(fileName, ":^") && !stringContains(fileName, directorySeparator));
|
||||
(fileName.includes(":^") && !fileName.includes(directorySeparator));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
||||
@@ -124,7 +124,6 @@ import {
|
||||
some,
|
||||
SourceFile,
|
||||
startsWith,
|
||||
stringContains,
|
||||
SymbolDisplayPart,
|
||||
SyntaxKind,
|
||||
TextChange,
|
||||
@@ -2960,7 +2959,7 @@ export class Session<TMessage = string> implements EventSender {
|
||||
}
|
||||
|
||||
// No need to analyze lib.d.ts
|
||||
const fileNamesInProject = fileNames!.filter(value => !stringContains(value, "lib.d.ts")); // TODO: GH#18217
|
||||
const fileNamesInProject = fileNames!.filter(value => !value.includes("lib.d.ts")); // TODO: GH#18217
|
||||
if (fileNamesInProject.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user