1
0
mirror of synced 2025-12-21 10:57:10 -05:00

optimization: hash lookup is faster than in-array check (#23079)

This commit is contained in:
Peter Bengtsson
2021-11-23 16:44:35 -05:00
committed by GitHub
parent feb0318d25
commit 0eb15bca49

View File

@@ -10,7 +10,7 @@ import removeFPTFromPath from '../../remove-fpt-from-path.js'
import readJsonFile from '../../read-json-file.js' import readJsonFile from '../../read-json-file.js'
const supportedVersions = Object.keys(allVersions) const supportedVersions = Object.keys(allVersions)
const supportedPlans = Object.values(allVersions).map((v) => v.plan) const supportedPlans = Object.values(allVersions).map((v) => v.plan)
const externalRedirects = Object.keys(readJsonFile('./lib/redirects/external-sites.json')) const externalRedirects = readJsonFile('./lib/redirects/external-sites.json')
// Matches any <a> tags with an href that starts with `/` // Matches any <a> tags with an href that starts with `/`
const matcher = (node) => const matcher = (node) =>
@@ -41,7 +41,7 @@ function getNewHref(node, languageCode, version) {
// Exceptions to link rewriting // Exceptions to link rewriting
if (href.startsWith('/assets')) return if (href.startsWith('/assets')) return
if (href.startsWith('/public')) return if (href.startsWith('/public')) return
if (externalRedirects.includes(href)) return if (href in externalRedirects) return
let newHref = href let newHref = href
// If the link has a hardcoded plan or version in it, do not update other than adding a language code // If the link has a hardcoded plan or version in it, do not update other than adding a language code