Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: improve string operations #382

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions benchmark/compare-branches.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ async function executeCommandOnBranch (command, branch) {
function parseBenchmarksStdout (text) {
const results = []

const lines = text.split('\n')
for (const line of lines) {
for (const line of text.split('\n')) {
const match = /^(.+?)(\.*) x (.+) ops\/sec .*$/.exec(line)
if (match !== null) {
results.push({
name: match[1],
alignedName: match[1] + match[2],
result: parseInt(match[3].split(',').join(''))
result: parseInt(match[3].replaceAll(',', ''))
})
}
}
Expand Down
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ Router.prototype._on = function _on (method, path, opts, handler, store) {
if (!this.caseSensitive) {
staticNodePath = staticNodePath.toLowerCase()
}
staticNodePath = staticNodePath.split('::').join(':')
staticNodePath = staticNodePath.split('%').join('%25')
staticNodePath = staticNodePath.replaceAll('::', ':')
staticNodePath = staticNodePath.replaceAll('%', '%25')
// add the static part of the route to the tree
currentNode = currentNode.createStaticChild(staticNodePath)
}
Expand Down Expand Up @@ -240,8 +240,8 @@ Router.prototype._on = function _on (method, path, opts, handler, store) {

let staticPart = pattern.slice(staticPartStartIndex, j)
if (staticPart) {
staticPart = staticPart.split('::').join(':')
staticPart = staticPart.split('%').join('%25')
staticPart = staticPart.replaceAll('::', ':')
staticPart = staticPart.replaceAll('%', '%25')
regexps.push(backtrack = escapeRegExp(staticPart))
}

Expand Down Expand Up @@ -328,8 +328,8 @@ Router.prototype.findRoute = function findNode (method, path, constraints = {})
if (!this.caseSensitive) {
staticNodePath = staticNodePath.toLowerCase()
}
staticNodePath = staticNodePath.split('::').join(':')
staticNodePath = staticNodePath.split('%').join('%25')
staticNodePath = staticNodePath.replaceAll('::', ':')
staticNodePath = staticNodePath.replaceAll('%', '%25')
// add the static part of the route to the tree
currentNode = currentNode.getStaticChild(staticNodePath)
if (currentNode === null) {
Expand Down Expand Up @@ -387,8 +387,8 @@ Router.prototype.findRoute = function findNode (method, path, constraints = {})

let staticPart = pattern.slice(staticPartStartIndex, j)
if (staticPart) {
staticPart = staticPart.split('::').join(':')
staticPart = staticPart.split('%').join('%25')
staticPart = staticPart.replaceAll('::', ':')
staticPart = staticPart.replaceAll('%', '%25')
regexps.push(backtrack = escapeRegExp(staticPart))
}

Expand Down
2 changes: 1 addition & 1 deletion lib/pretty-print.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function printObjectTree (obj, parentPrefix = '') {
const childPrefix = isLast ? ' ' : '│ '

const nodeData = value[treeDataSymbol] || ''
const prefixedNodeData = nodeData.split('\n').join('\n' + parentPrefix + childPrefix)
const prefixedNodeData = nodeData.replaceAll('\n', '\n' + parentPrefix + childPrefix)

tree += parentPrefix + nodePrefix + key + prefixedNodeData + '\n'
tree += printObjectTree(value, parentPrefix + childPrefix)
Expand Down
2 changes: 1 addition & 1 deletion lib/strategies/accept-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SemVerStore.prototype.set = function (version, store) {
if (typeof version !== 'string') {
throw new TypeError('Version should be a string')
}
let [major, minor, patch] = version.split('.')
let [major, minor, patch] = version.split('.', 3)

if (isNaN(major)) {
throw new TypeError('Major version must be a numeric value')
Expand Down
Loading