From 5e9861369f2948dd6bdc9b896be8c2df7da96d8d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 26 May 2026 06:15:34 +0000 Subject: [PATCH] Avoid object allocation in onDraw Moved `RectF` allocation in `TouchButtonView.onDraw` to a class member and updated it with `.set()` instead of creating a new object every frame. This avoids garbage collection overhead during animations. Co-authored-by: SirDank <52797753+SirDank@users.noreply.github.com> --- .../main/java/com/skarm/launcher/touch/TouchControlViews.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/launcher/app/src/main/java/com/skarm/launcher/touch/TouchControlViews.kt b/launcher/app/src/main/java/com/skarm/launcher/touch/TouchControlViews.kt index 2aba2cf..5a04e93 100644 --- a/launcher/app/src/main/java/com/skarm/launcher/touch/TouchControlViews.kt +++ b/launcher/app/src/main/java/com/skarm/launcher/touch/TouchControlViews.kt @@ -222,12 +222,14 @@ class TouchButtonView(context: Context, node: ControlNode) : BaseTouchControl(co private var isPressedState = false private var isToggledOn = false + private val buttonRect = RectF() + override fun onDraw(canvas: Canvas) { val centerX = width / 2f val centerY = height / 2f val size = min(width, height).toFloat() - val rect = RectF( + buttonRect.set( centerX - size / 2f, centerY - size / 2f, centerX + size / 2f, @@ -238,7 +240,7 @@ class TouchButtonView(context: Context, node: ControlNode) : BaseTouchControl(co // Use a rounded square instead of a circle val cornerRadius = size * 0.25f - canvas.drawRoundRect(rect, cornerRadius, cornerRadius, bgPaint) + canvas.drawRoundRect(buttonRect, cornerRadius, cornerRadius, bgPaint) // Draw label if (node.label.isNotEmpty()) {