mirror of
https://github.com/honojs/hono.git
synced 2024-11-29 09:43:20 +01:00
perf: use ===
instead of startsWith
and endsWith
(#1053)
This commit is contained in:
parent
0a19deaa5b
commit
64ddf093d6
@ -8,7 +8,7 @@ export class PatternRouter<T> implements Router<T> {
|
||||
private dNames: Record<string, number> = {} // Short name of duplicatedNames
|
||||
|
||||
add(method: string, path: string, handler: T) {
|
||||
const endsWithWildcard = path.endsWith('*')
|
||||
const endsWithWildcard = path[path.length - 1] === '*'
|
||||
if (endsWithWildcard) {
|
||||
path = path.slice(0, -2)
|
||||
}
|
||||
|
@ -87,13 +87,13 @@ export const mergePath = (...paths: string[]): string => {
|
||||
|
||||
for (let path of paths) {
|
||||
/* ['/hey/','/say'] => ['/hey', '/say'] */
|
||||
if (p.endsWith('/')) {
|
||||
if (p[p.length - 1] === '/') {
|
||||
p = p.slice(0, -1)
|
||||
endsWithSlash = true
|
||||
}
|
||||
|
||||
/* ['/hey','say'] => ['/hey', '/say'] */
|
||||
if (!path.startsWith('/')) {
|
||||
if (path[0] !== '/') {
|
||||
path = `/${path}`
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ export class PatternRouter<T> implements Router<T> {
|
||||
private dNames: Record<string, number> = {} // Short name of duplicatedNames
|
||||
|
||||
add(method: string, path: string, handler: T) {
|
||||
const endsWithWildcard = path.endsWith('*')
|
||||
const endsWithWildcard = path[path.length - 1] === '*'
|
||||
if (endsWithWildcard) {
|
||||
path = path.slice(0, -2)
|
||||
}
|
||||
|
@ -87,13 +87,13 @@ export const mergePath = (...paths: string[]): string => {
|
||||
|
||||
for (let path of paths) {
|
||||
/* ['/hey/','/say'] => ['/hey', '/say'] */
|
||||
if (p.endsWith('/')) {
|
||||
if (p[p.length - 1] === '/') {
|
||||
p = p.slice(0, -1)
|
||||
endsWithSlash = true
|
||||
}
|
||||
|
||||
/* ['/hey','say'] => ['/hey', '/say'] */
|
||||
if (!path.startsWith('/')) {
|
||||
if (path[0] !== '/') {
|
||||
path = `/${path}`
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user