Skip to content

Commit c852e87

Browse files
committed
Change Util.applyInverseTransform to use the point-argument as an in/out parameter
This will help reduce the total number of Array allocations, which cannot hurt.
1 parent fa643bb commit c852e87

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/display/display_utils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,9 @@ class PageViewport {
287287
* @see {@link convertToViewportPoint}
288288
*/
289289
convertToPdfPoint(x, y) {
290-
return Util.applyInverseTransform([x, y], this.transform);
290+
const p = [x, y];
291+
Util.applyInverseTransform(p, this.transform);
292+
return p;
291293
}
292294
}
293295

src/shared/util.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -758,10 +758,10 @@ class Util {
758758
}
759759

760760
static applyInverseTransform(p, m) {
761+
const [p0, p1] = p;
761762
const d = m[0] * m[3] - m[1] * m[2];
762-
const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
763-
const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
764-
return [xt, yt];
763+
p[0] = (p0 * m[3] - p1 * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
764+
p[1] = (-p0 * m[1] + p1 * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
765765
}
766766

767767
// Applies the transform to the rectangle and finds the minimum axially

0 commit comments

Comments
 (0)