Skip to content

Commit 032440e

Browse files
authored
perf: reduce array allocations (#1542)
1 parent 212ba3c commit 032440e

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

lib/hacks/gradient.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ class Gradient extends Value {
352352

353353
node.nodes = []
354354
for (let param of params) {
355-
node.nodes = node.nodes.concat(param)
355+
node.nodes.push(...param)
356356
}
357357

358358
node.nodes.unshift(

lib/hacks/grid-utils.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,14 @@ exports.prefixTrackValue = prefixTrackValue
135135
function prefixTrackValue({ gap, value }) {
136136
let result = parser(value).nodes.reduce((nodes, node) => {
137137
if (node.type === 'function' && node.value === 'repeat') {
138-
return nodes.concat({
138+
nodes.push({
139139
type: 'word',
140140
value: transformRepeat(node, { gap })
141141
})
142+
return nodes
142143
}
143144
if (gap && node.type === 'space') {
144-
return nodes.concat(
145+
nodes.push(
145146
{
146147
type: 'space',
147148
value: ' '
@@ -152,8 +153,10 @@ function prefixTrackValue({ gap, value }) {
152153
},
153154
node
154155
)
156+
return nodes
155157
}
156-
return nodes.concat(node)
158+
nodes.push(node)
159+
return nodes
157160
}, [])
158161

159162
return parser.stringify(result)
@@ -1046,7 +1049,8 @@ function normalizeRowColumn(str) {
10461049
if (node.type === 'space') {
10471050
return result
10481051
}
1049-
return result.concat(parser.stringify(node))
1052+
result.push(parser.stringify(node))
1053+
return result
10501054
}, [])
10511055

10521056
return normalized

lib/transition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class Transition {
314314
if (param[param.length - 1].type !== 'div') {
315315
param.push(this.div(params))
316316
}
317-
nodes = nodes.concat(param)
317+
nodes.push(...param)
318318
}
319319
if (nodes[0].type === 'div') {
320320
nodes = nodes.slice(1)

0 commit comments

Comments
 (0)