Skip to content

Commit 4a426d9

Browse files
committed
Use the faster bitwise operator instead of Math.floor and parseInt.
See stomita/ios-imagefile-megapixel@a8a96e47bb25c6 ad59f84a9144a38198ce974cfc and http://jsperf.com/math-floor-vs-math-round-vs-parseint/33
1 parent c9df582 commit 4a426d9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

load-image.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@
145145
0,
146146
sw,
147147
sh,
148-
Math.floor(sx * width / iw),
149-
Math.floor(sy * height / ih / vertSquashRatio),
148+
(sx * width / iw) << 0,
149+
(sy * height / ih / vertSquashRatio) << 0,
150150
Math.ceil(sw * width / iw),
151151
Math.ceil(sh * height / ih / vertSquashRatio)
152152
);
@@ -173,16 +173,16 @@
173173
(options.minHeight || height) / height
174174
);
175175
if (scale > 1) {
176-
width = parseInt(width * scale, 10);
177-
height = parseInt(height * scale, 10);
176+
width = (width * scale) << 0;
177+
height = (height * scale) << 0;
178178
}
179179
scale = Math.min(
180180
(options.maxWidth || width) / width,
181181
(options.maxHeight || height) / height
182182
);
183183
if (scale < 1) {
184-
width = parseInt(width * scale, 10);
185-
height = parseInt(height * scale, 10);
184+
width = (width * scale) << 0;
185+
height = (height * scale) << 0;
186186
}
187187
if (img.getContext || (options.canvas && canvas.getContext)) {
188188
canvas.width = width;

0 commit comments

Comments
 (0)