Skip to content

Commit f75e32b

Browse files
committed
chore: replace deep copy with shallow spread in getTransformedTokenStream
\`copy(token)\` performed a full recursive deep copy even though all mutations on the result only replace top-level properties (\`ref\`, \`xpr\`, \`args\`, \`cast\`). A shallow spread \`{ ...token }\` is sufficient. Also guards against string tokens spreading into character-indexed objects, and drops the inner redundant \`copy(token)\` in the \`\$self\`/\`outerAlias\` branch.
1 parent 2316210 commit f75e32b

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

db-service/lib/cqn4sql.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,8 +1812,7 @@ function cqn4sql(originalQuery, model, useTechnicalAlias = true) {
18121812
// reject virtual elements in expressions as they will lead to a sql error down the line
18131813
if (lhsDef?.virtual) throw new Error(`Virtual elements are not allowed in expressions`)
18141814

1815-
let result = is_regexp(token?.val) ? token : copy(token) // REVISIT: too expensive!
1816-
// REVISIT: required because we copy the token above and lose the not enumerable "param: false"
1815+
let result = typeof token !== 'object' || is_regexp(token?.val) ? token : { ...token }
18171816
if (typeof token === 'object' && 'val' in token && 'param' in token) Object.defineProperty(result, 'param', { value: token.param })
18181817
if (token.ref) {
18191818
const { definition } = token.$refLinks.at(-1)
@@ -1830,7 +1829,6 @@ function cqn4sql(originalQuery, model, useTechnicalAlias = true) {
18301829
const stepToFind = token.ref[1]?.id || token.ref[1]
18311830
const outerAlias = outerQuery.$combinedElements?.[stepToFind]?.[0].index
18321831
if (outerAlias) {
1833-
let result = copy(token)
18341832
result.ref = [outerAlias, token.flatName]
18351833
transformedTokenStream.push(result)
18361834
continue

0 commit comments

Comments
 (0)