Skip to content

Commit 53cbdcc

Browse files
committed
perf(mdviewer): use bitwise shift for binary-search midpoint
Hot path in _balancedPack: >>1 is faster than Math.floor for the midpoint of two non-negative ints, and the values here stay well under 2^31. Adds a local no-bitwise eslint disable with rationale.
1 parent cf2037b commit 53cbdcc

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/extensionsIntegrated/Phoenix-live-preview/markdown-line-wrap.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ define(function (require, exports, module) {
172172
let hi = width;
173173
let best = greedy;
174174
while (lo <= hi) {
175-
const mid = Math.floor((lo + hi) / 2);
175+
// Midpoint of two non-negative ints; >>1 is faster than
176+
// Math.floor and the values stay well under 2^31.
177+
// eslint-disable-next-line no-bitwise
178+
const mid = (lo + hi) >> 1;
176179
const trial = _packTokens(tokens, mid);
177180
if (trial.length <= N) {
178181
best = trial;

0 commit comments

Comments
 (0)