Skip to content

Commit

Permalink
esm: optimize string checks and slicing with direct index access
Browse files Browse the repository at this point in the history
  • Loading branch information
Mert Can Altin authored and Mert Can Altin committed Oct 17, 2024
1 parent 4d6d7d6 commit 6c36de3
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/internal/modules/esm/fetch_module.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ const {
ObjectPrototypeHasOwnProperty,
PromisePrototypeThen,
SafeMap,
StringPrototypeEndsWith,
StringPrototypeSlice,
StringPrototypeStartsWith,
} = primordials;
const {
Buffer: { concat: BufferConcat },
Expand Down Expand Up @@ -248,10 +245,10 @@ allowList.addRange('127.0.0.1', '127.255.255.255');
async function isLocalAddress(hostname) {
try {
if (
StringPrototypeStartsWith(hostname, '[') &&
StringPrototypeEndsWith(hostname, ']')
hostname[0] === '[' &&
hostname[hostname.length - 1] === ']'
) {
hostname = StringPrototypeSlice(hostname, 1, -1);
hostname = hostname.slice(1, -1);
}
const addr = await dnsLookup(hostname, { order: 'verbatim' });
const ipv = addr.family === 4 ? 'ipv4' : 'ipv6';
Expand Down

0 comments on commit 6c36de3

Please sign in to comment.