Use template strings instead of join for speed
This commit is contained in:
@@ -27,7 +27,7 @@ type SubscribeOpts = {onEvent?: EventCallback; onEose?: EoseCallback}
|
||||
type PublishOpts = {verb?: string; onOk?: OkCallback; onError?: ErrorCallback}
|
||||
type DiffOpts = {onError?: ErrorCallback; onMessage?: DiffMessageCallback; onClose?: CloseCallback}
|
||||
|
||||
const createSubId = (prefix: string) => [prefix, Math.random().toString().slice(2, 10)].join("-")
|
||||
const createSubId = (prefix: string) => `${prefix}-${Math.random().toString().slice(2, 10)}`
|
||||
|
||||
export class Executor {
|
||||
constructor(readonly target: Target) {}
|
||||
|
||||
@@ -32,7 +32,7 @@ export const nip04 = {
|
||||
export const nip44 = {
|
||||
getSharedSecret: cached({
|
||||
maxSize: 10000,
|
||||
getKey: ([secret, pubkey]) => [secret, pubkey].join(":"),
|
||||
getKey: ([secret, pubkey]) => `${secret}:${pubkey}`,
|
||||
getValue: ([secret, pubkey]: string[]) =>
|
||||
nt44.v2.utils.getConversationKey(hexToBytes(secret), pubkey),
|
||||
}),
|
||||
|
||||
@@ -49,7 +49,7 @@ export class Address {
|
||||
return new Address(event.kind, event.pubkey, identifier, relays)
|
||||
}
|
||||
|
||||
toString = () => [this.kind, this.pubkey, this.identifier].join(":")
|
||||
toString = () => `${this.kind}:${this.pubkey}:${this.identifier}`
|
||||
|
||||
toNaddr = () => naddrEncode(this)
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ const _hasValidSignature = cached<string, boolean, [SignedEvent]>({
|
||||
maxSize: 10000,
|
||||
getKey: ([e]: [SignedEvent]) => {
|
||||
try {
|
||||
return [getEventHash(e), e.sig].join(":")
|
||||
return `${getEventHash(e)}:${e.sig}`
|
||||
} catch (err) {
|
||||
return "invalid"
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ export const getFilterId = (filter: Filter) => {
|
||||
const v = filter[k as keyof Filter]
|
||||
const s = Array.isArray(v) ? v.join(",") : v
|
||||
|
||||
parts.push([k, s].join(":"))
|
||||
parts.push(`${k}:${s}`)
|
||||
}
|
||||
|
||||
return hash(parts.join("|"))
|
||||
|
||||
Reference in New Issue
Block a user