From a0103af11df7c98bed1e905951299381bd7d4320 Mon Sep 17 00:00:00 2001 From: Yang Jun Date: Mon, 6 Jul 2026 20:37:34 +0800 Subject: [PATCH] refactor(filters): simplify join output-size accounting Sum stringified element lengths in a single pass and keep the guarded Array.prototype.join for the result, instead of building an intermediate parts array. Co-authored-by: Cursor --- src/filters/array.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/filters/array.ts b/src/filters/array.ts index 0a28db9e8..57a7d802d 100644 --- a/src/filters/array.ts +++ b/src/filters/array.ts @@ -8,16 +8,10 @@ import { EmptyDrop } from '../drop' export const join = argumentsToValue(function (this: FilterImpl, v: any[], arg: string) { const array = toArray(v) const sep = isNil(arg) ? ' ' : stringify(arg) - const parts: string[] = [] - let outputSize = array.length > 0 ? sep.length * (array.length - 1) : 0 - for (let i = 0; i < array.length; i++) { - const item = array[i] - const part = isNil(item) ? '' : String(item) - outputSize += part.length - parts.push(part) - } + let outputSize = sep.length * Math.max(array.length - 1, 0) + for (let i = 0; i < array.length; i++) outputSize += String(array[i]).length this.context.memoryLimit.use(outputSize) - return parts.join(sep) + return Array.prototype.join.call(array, sep) }) export const last = argumentsToValue(function (this: FilterImpl, v: any) { return isArrayLike(v) ? readArrayElement(v, -1, this.context.ownPropertyOnly) : ''