Skip to content

Commit b060516

Browse files
authored
[perf] Hoist render queue sorting fn
1 parent bf39376 commit b060516

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/component.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,16 @@ export function enqueueRender(c) {
205205
}
206206
}
207207

208+
/**
209+
* @param {import('./internal').Component} a
210+
* @param {import('./internal').Component} b
211+
*/
212+
const depthSort = (a, b) => a._vnode._depth - b._vnode._depth;
213+
208214
/** Flush the render queue by rerendering all queued components */
209215
function process() {
210216
let c;
211-
rerenderQueue.sort((a, b) => a._vnode._depth - b._vnode._depth);
217+
rerenderQueue.sort(depthSort);
212218
// Don't update `renderCount` yet. Keep its value non-zero to prevent unnecessary
213219
// process() calls from getting scheduled while `queue` is still being consumed.
214220
while ((c = rerenderQueue.shift())) {
@@ -219,7 +225,7 @@ function process() {
219225
// When i.e. rerendering a provider additional new items can be injected, we want to
220226
// keep the order from top to bottom with those new items so we can handle them in a
221227
// single pass
222-
rerenderQueue.sort((a, b) => a._vnode._depth - b._vnode._depth);
228+
rerenderQueue.sort(depthSort);
223229
}
224230
}
225231
}

0 commit comments

Comments
 (0)