perf: replace String and Array indexOf method calls with includes method call (#55482)

This commit is contained in:
Sampo Kivistö
2023-08-25 11:27:55 -07:00
committed by GitHub
parent c3c5abb3a7
commit ec2bd4e252
46 changed files with 98 additions and 124 deletions
+4 -4
View File
@@ -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);
}
}
+1 -1
View File
@@ -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() {
+2 -3
View File
@@ -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 */
+1 -2
View File
@@ -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;
}