0
0
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:
Yusuke Wada 2023-04-30 21:18:32 +09:00 committed by GitHub
parent 0a19deaa5b
commit 64ddf093d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 6 deletions

View File

@ -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)
}

View File

@ -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}`
}

View File

@ -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)
}

View File

@ -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}`
}