Unverified Commit c5f5b3c9 authored by Yegor's avatar Yegor Committed by GitHub

Reuse matrix instance for transient transforms in _transformRect for fewer allocations (#35132)

parent 91663376
......@@ -3599,15 +3599,24 @@ class _SemanticsGeometry {
}
}
// A matrix used to store transient transform data.
//
// Reusing this matrix avoids allocating a new matrix every time a temporary
// matrix is needed.
//
// This instance should never be returned to the caller. Otherwise, the data
// stored in it will be overwritten unpredictably by subsequent reuses.
static final Matrix4 _temporaryTransformHolder = Matrix4.zero();
/// From parent to child coordinate system.
static Rect _transformRect(Rect rect, RenderObject parent, RenderObject child) {
if (rect == null)
return null;
if (rect.isEmpty)
return Rect.zero;
final Matrix4 transform = Matrix4.identity();
parent.applyPaintTransform(child, transform);
return MatrixUtils.inverseTransformRect(transform, rect);
_temporaryTransformHolder.setIdentity(); // clears data from a previous call
parent.applyPaintTransform(child, _temporaryTransformHolder);
return MatrixUtils.inverseTransformRect(_temporaryTransformHolder, rect);
}
static Rect _intersectRects(Rect a, Rect b) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment