From 326fa4a4692fe8ef6f9887daff91c5dda6bf0b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8A=E6=92=92=E5=B0=94?= <1533540012@qq.com> Date: Mon, 16 Dec 2019 14:20:17 +0800 Subject: [PATCH] Use zero-fill right shift instead of Math.floor For positive numbers, binary displacement is better. --- packages/scheduler/src/SchedulerMinHeap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/scheduler/src/SchedulerMinHeap.js b/packages/scheduler/src/SchedulerMinHeap.js index cbf7a649e962..467cc92a2275 100644 --- a/packages/scheduler/src/SchedulerMinHeap.js +++ b/packages/scheduler/src/SchedulerMinHeap.js @@ -41,7 +41,7 @@ export function pop(heap: Heap): Node | null { function siftUp(heap, node, i) { let index = i; while (true) { - const parentIndex = Math.floor((index - 1) / 2); + const parentIndex = (index - 1) >>> 1; const parent = heap[parentIndex]; if (parent !== undefined && compare(parent, node) > 0) { // The parent is larger. Swap positions.