Skip to content

Commit 235dc74

Browse files
authored
perf: replace startsWith with strict equality (#6094)
1 parent a2744ea commit 235dc74

File tree

8 files changed

+11
-11
lines changed

8 files changed

+11
-11
lines changed

docs/.vitepress/verify-anchors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function verifyAnchorsOnPage(page: string, slugs: Set<string>) {
4040
let match: (RegExpExecArray & { groups?: { href?: string } }) | null;
4141
while ((match = markdownLinkRegExp.exec(text)) !== null) {
4242
const [href] = match;
43-
if (href.startsWith('#')) {
43+
if (href[0] === '#') {
4444
const anchor = href.slice(1);
4545
if (!slugs.has(anchor)) {
4646
console.log(slugs);

docs/repl/helpers/query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export async function useUpdateStoresFromQuery() {
1616
try {
1717
if (query.shareable) {
1818
const rawJson = atob(query.shareable.replace(/_/g, '/').replace(/-/g, '+'));
19-
const json = rawJson.startsWith('%') ? decodeURIComponent(rawJson) : rawJson;
19+
const json = rawJson[0] === '%' ? decodeURIComponent(rawJson) : rawJson;
2020
const {
2121
modules: queryModules,
2222
options: queryOptions,

scripts/test-options.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ for (const line of splitHelpText) {
7373
}
7474
}
7575

76-
const helpOptionLines = splitHelpText.filter(line => line.startsWith('-'));
76+
const helpOptionLines = splitHelpText.filter(line => line[0] === '-');
7777

7878
const cliFlagsText = commandReferenceText
7979
.split('\n## ')
@@ -85,7 +85,7 @@ const cliMarkdownSection = cliFlagsText.match(/```\n([\S\s]*?)\n```/);
8585
if (!cliMarkdownSection) {
8686
throw new Error('Could not find markdown section in "Command line flags" section.');
8787
}
88-
const optionListLines = cliMarkdownSection[1].split('\n').filter(line => line.startsWith('-'));
88+
const optionListLines = cliMarkdownSection[1].split('\n').filter(line => line[0] === '-');
8989

9090
for (const [index, line] of helpOptionLines.entries()) {
9191
const optionListLine = optionListLines[index];

src/Chunk.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ export default class Chunk {
966966
variable.isNamespace &&
967967
namespaceInteropHelpersByInteropType[interop(module.id)] &&
968968
(this.imports.has(variable) ||
969-
!this.exportNamesByVariable.get(variable)?.every(name => name.startsWith('*')))
969+
!this.exportNamesByVariable.get(variable)?.every(name => name[0] === '*'))
970970
) {
971971
// We only need to deconflict it if the namespace is actually
972972
// created as a variable, i.e. because it is used internally or
@@ -1143,7 +1143,7 @@ export default class Chunk {
11431143
return idWithoutExtension.slice(preserveModulesRoot.length).replace(/^[/\\]/, '');
11441144
} else {
11451145
// handle edge case in Windows
1146-
if (this.inputBase === '/' && !idWithoutExtension.startsWith('/')) {
1146+
if (this.inputBase === '/' && idWithoutExtension[0] !== '/') {
11471147
return relative(this.inputBase, idWithoutExtension.replace(/^[a-zA-Z]:[/\\]/, '/'));
11481148
}
11491149
return relative(this.inputBase, idWithoutExtension);

src/utils/getLogFilter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const getLogFilter: GetLogFilter = filters => {
55
if (filters.length === 0) return () => true;
66
const normalizedFilters = filters.map(filter =>
77
filter.split('&').map(subFilter => {
8-
const inverted = subFilter.startsWith('!');
8+
const inverted = subFilter[0] === '!';
99
if (inverted) subFilter = subFilter.slice(1);
1010
const [key, ...value] = subFilter.split(':');
1111
return { inverted, key: key.split('.'), parts: value.join(':').split('*') };

src/utils/options/normalizeInputOptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const getIdMatcher = <T extends any[]>(
9797
return () => true;
9898
}
9999
if (typeof option === 'function') {
100-
return (id, ...parameters) => (!id.startsWith('\0') && option(id, ...parameters)) || false;
100+
return (id, ...parameters) => (id[0] !== '\0' && option(id, ...parameters)) || false;
101101
}
102102
if (option) {
103103
const ids = new Set<string>();
@@ -241,7 +241,7 @@ const getHasModuleSideEffects = (
241241
}
242242
if (typeof moduleSideEffectsOption === 'function') {
243243
return (id, external) =>
244-
id.startsWith('\0') ? true : moduleSideEffectsOption(id, external) !== false;
244+
id[0] === '\0' ? true : moduleSideEffectsOption(id, external) !== false;
245245
}
246246
if (Array.isArray(moduleSideEffectsOption)) {
247247
const ids = new Set(moduleSideEffectsOption);

test/function/samples/external-ignore-reserved-null-marker/_config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = defineTest({
22
description: 'external function ignores \\0 started ids',
33
options: {
44
external(id) {
5-
if (id.startsWith('\0')) {
5+
if (id[0] === '\0') {
66
throw new Error('\\0 started ids should not be tested as external');
77
}
88
return true;

test/testHelpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ const replaceStringifyValues = (key, value) => {
497497
}
498498
}
499499

500-
return key.startsWith('_')
500+
return key[0] === '_'
501501
? undefined
502502
: typeof value == 'bigint'
503503
? `~BigInt${value.toString()}`

0 commit comments

Comments
 (0)