Skip to content
Myr

perf: Make ParamMap Array<[key, value]>. (#113)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Taku Amano · committed by GitHub · parent 68baca0 · Browse files · 3 files+10 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+10 added−13 removed

  • other:+10 added−13 removed

3 files+10 added−13 removed

modified:src/router/reg-exp-router/node.ts+2 added-4 removed
modified:src/router/reg-exp-router/router.ts+7 added-8 removed
50 unmodified lines
5152 const index = match.indexOf('', 1)53 const [handler, paramMap] = handlers[replacementMap[index]]54 const params: { [key: string]: string } = {}55 const keys = Object.keys(paramMap)56 for (let i = 0; i < keys.length; i++) {57 params[keys[i]] = match[paramMap[keys[i]]]55 for (let i = 0; i < paramMap.length; i++) {56 params[paramMap[i][0]] = match[paramMap[i][1]]57 }58 return new Result(handler, params)59 }60
24 unmodified lines
85 return86 }8788 if (routes.length === 1 && routes[0][0] === '*') {90 this.matchers[method] = [true, null, [[routes[0][1], {}]]]89 this.matchers[method] = [true, null, [[routes[0][1], []]]]90 return91 }9293 if (routes.length === 1 && !routes[0][0].match(/:/)) {
1 unmodified line
95 const tmp = routes[0][0].endsWith('*')96 ? routes[0][0].replace(/\/\*$/, '(?:$|/)') // /path/to/* => /path/to(?:$|/)97 : `${routes[0][0]}$` // /path/to/action => /path/to/action$98 const regExpStr = `^${tmp.replace(/\*/g, '[^/]+')}` // /prefix/*/path/to => /prefix/[^/]+/path/to100 this.matchers[method] = [new RegExp(regExpStr), null, [[routes[0][1], {}]]]99 this.matchers[method] = [new RegExp(regExpStr), null, [[routes[0][1], []]]]100 return101 }102103 for (let i = 0; i < routes.length; i++) {
3 unmodified lines
107108 const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp()109 for (let i = 0; i < handlers.length; i++) {110 const paramMap = handlers[i][1]112 Object.keys(paramMap).forEach((k) => {113 paramMap[k] = paramReplacementMap[paramMap[k]]114 })111 for (let i = 0; i < paramMap.length; i++) {112 paramMap[i][1] = paramReplacementMap[paramMap[i][1]]113 }114 }115116 this.matchers[method] = [new RegExp(regexp), indexReplacementMap, handlers]117 }
1 unmodified line
modified:src/router/reg-exp-router/trie.ts+1 added-1 removed