From 1373a8eb581fe3c8e9a036e69042015f98a7e346 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Thu, 10 Nov 2011 19:59:13 -0800 Subject: [PATCH] Localized optimizations in views and bitmaps * Don't call context.getResources() redundantly when unnecessary; similarly for Resources.getCompatibilityInfo() * During bitmap creation, don't bother clearing to 0: it's unnecessary because now that the raw bits are stored in a VM-side byte array, it was cleared at initialization time. Also, don't use the sanity- checking public entry point to erase to a color, because we know that we're by definition in a "legal" path to erase to the initial contents and don't need to incur the overhead of the (inappropriate) sanity checking. Change-Id: Idaca4d64fdecefd5d51337646ead32e1db510e02 --- core/java/android/widget/EdgeEffect.java | 2 +- core/java/android/widget/TextView.java | 12 +++++++----- graphics/java/android/graphics/Bitmap.java | 7 +++++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/core/java/android/widget/EdgeEffect.java b/core/java/android/widget/EdgeEffect.java index fd2abc249d95f..326587e6e7cb7 100644 --- a/core/java/android/widget/EdgeEffect.java +++ b/core/java/android/widget/EdgeEffect.java @@ -129,7 +129,7 @@ public class EdgeEffect { mEdge = res.getDrawable(R.drawable.overscroll_edge); mGlow = res.getDrawable(R.drawable.overscroll_glow); - mMinWidth = (int) (context.getResources().getDisplayMetrics().density * MIN_WIDTH + 0.5f); + mMinWidth = (int) (res.getDisplayMetrics().density * MIN_WIDTH + 0.5f); mInterpolator = new DecelerateInterpolator(); } diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index bc8721accf4f7..b106cc520ce0f 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -24,6 +24,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.content.res.ColorStateList; +import android.content.res.CompatibilityInfo; import android.content.res.Resources; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; @@ -449,18 +450,19 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener super(context, attrs, defStyle); mText = ""; + final Resources res = getResources(); + final CompatibilityInfo compat = res.getCompatibilityInfo(); + mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); - mTextPaint.density = getResources().getDisplayMetrics().density; - mTextPaint.setCompatibilityScaling( - getResources().getCompatibilityInfo().applicationScale); + mTextPaint.density = res.getDisplayMetrics().density; + mTextPaint.setCompatibilityScaling(compat.applicationScale); // If we get the paint from the skin, we should set it to left, since // the layout always wants it to be left. // mTextPaint.setTextAlign(Paint.Align.LEFT); mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG); - mHighlightPaint.setCompatibilityScaling( - getResources().getCompatibilityInfo().applicationScale); + mHighlightPaint.setCompatibilityScaling(compat.applicationScale); mMovement = getDefaultMovementMethod(); mTransformation = null; diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index 79acd552b5832..380b3d86718fb 100644 --- a/graphics/java/android/graphics/Bitmap.java +++ b/graphics/java/android/graphics/Bitmap.java @@ -604,10 +604,13 @@ public final class Bitmap implements Parcelable { } Bitmap bm = nativeCreate(null, 0, width, width, height, config.nativeInt, true); if (config == Config.ARGB_8888 && !hasAlpha) { - bm.eraseColor(0xff000000); + nativeErase(bm.mNativeBitmap, 0xff000000); nativeSetHasAlpha(bm.mNativeBitmap, hasAlpha); } else { - bm.eraseColor(0); + // No need to initialize it to zeroes; it is backed by a VM byte array + // which is by definition preinitialized to all zeroes. + // + //nativeErase(bm.mNativeBitmap, 0); } return bm; }