From 63c885f881b64a20466fc351731cd7018e6d7a80 Mon Sep 17 00:00:00 2001 From: Gilles Debunne Date: Wed, 7 Sep 2011 14:27:38 -0700 Subject: [PATCH] Bug 5250788: Fix memory consumption issues in TextPaint. The increased size array was discarded in set. Reuse it instead if possible to avoid more size increases later. Change-Id: I9ab95ed0f4d4613dd1e28f02894bb19ecee7df41 --- core/java/android/text/TextPaint.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/java/android/text/TextPaint.java b/core/java/android/text/TextPaint.java index 625d8693dbde1..afd989256b88c 100644 --- a/core/java/android/text/TextPaint.java +++ b/core/java/android/text/TextPaint.java @@ -72,8 +72,15 @@ public class TextPaint extends Paint { linkColor = tp.linkColor; drawableState = tp.drawableState; density = tp.density; - underlineColors = tp.underlineColors; - underlineThicknesses = tp.underlineThicknesses; + + if (tp.underlineColors != null) { + if (underlineColors == null || underlineColors.length < tp.underlineCount) { + underlineColors = new int[tp.underlineCount]; + underlineThicknesses = new float[tp.underlineCount]; + } + System.arraycopy(tp.underlineColors, 0, underlineColors, 0, tp.underlineCount); + System.arraycopy(tp.underlineThicknesses, 0, underlineThicknesses, 0, tp.underlineCount); + } underlineCount = tp.underlineCount; }