Skip to content
Myr

perf(utils/url): use `slice` + `indexOf` for `getPath()` (#2376)

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

* perf(utils/url): use `slice` + `indexOf` for `getPath()` * denoify

authored by Yusuke Wada · committed by GitHub · parent c2a2136 · Browse files · 5 files+35 added−6 removed
This commit

State

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

Diff stats

5 files+35 added−6 removed

  • other:+35 added−6 removed

5 files+35 added−6 removed

added:benchmarks/utils/src/get-path.ts+20 added
added:benchmarks/utils/.gitignore+2 added
1yarn.lock2bun.lockb
added:benchmarks/utils/package.json+5 added
modified:deno_dist/utils/url.ts+4 added-3 removed
68 unmodified lines
69 return null70}7172export const getPath = (request: Request): string => {73 // Optimized: RegExp is faster than indexOf() + slice()74 const match = request.url.match(/^https?:\/\/[^/]+(\/[^?]*)/)75 return match ? match[1] : ''73 // Optimized: indexOf() + slice() is faster than RegExp74 const url = request.url75 const queryIndex = url.indexOf('?', 8)76 return url.slice(url.indexOf('/', 8), queryIndex === -1 ? undefined : queryIndex)77}7879export const getQueryStrings = (url: string): string => {80 const queryIndex = url.indexOf('?', 8)
188 unmodified lines
modified:src/utils/url.ts+4 added-3 removed
68 unmodified lines
69 return null70}7172export const getPath = (request: Request): string => {73 // Optimized: RegExp is faster than indexOf() + slice()74 const match = request.url.match(/^https?:\/\/[^/]+(\/[^?]*)/)75 return match ? match[1] : ''73 // Optimized: indexOf() + slice() is faster than RegExp74 const url = request.url75 const queryIndex = url.indexOf('?', 8)76 return url.slice(url.indexOf('/', 8), queryIndex === -1 ? undefined : queryIndex)77}7879export const getQueryStrings = (url: string): string => {80 const queryIndex = url.indexOf('?', 8)
188 unmodified lines