Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4924ae8d authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 618 into donut

* changes:
  Fixes #1816088. Avoid initializing empty Rects when they are useless, especially in Zygote.
parents e4de845e 23bd84ce
Loading
Loading
Loading
Loading
+65 −50
Original line number Diff line number Diff line
@@ -96,11 +96,12 @@ import android.util.TypedValue;
 * and Internationalization</a>.
 */
public abstract class Drawable {
    private static final Rect ZERO_BOUNDS_RECT = new Rect();

    private int[] mStateSet = StateSet.WILD_CARD;
    private int mLevel = 0;
    private int mChangingConfigurations = 0;
    private Rect mBounds = new Rect();
    private Rect mBounds = ZERO_BOUNDS_RECT;
    /*package*/ Callback mCallback = null;
    private boolean mVisible = true;

@@ -119,6 +120,10 @@ public abstract class Drawable {
    public void setBounds(int left, int top, int right, int bottom) {
        Rect oldBounds = mBounds;

        if (oldBounds == ZERO_BOUNDS_RECT) {
            oldBounds = mBounds = new Rect();
        }

        if (oldBounds.left != left || oldBounds.top != top ||
                oldBounds.right != right || oldBounds.bottom != bottom) {
            mBounds.set(left, top, right, bottom);
@@ -150,7 +155,7 @@ public abstract class Drawable {
     * Return a copy of the drawable's bounds in a new Rect. This returns the
     * same values as getBounds(), but the returned object is guaranteed to not
     * be changed later by the drawable (i.e. it retains no reference to this
     * rect). If the caller already has a Rect allocated, call copyBounds(rect)
     * rect). If the caller already has a Rect allocated, call copyBounds(rect).
     *
     * @return A copy of the drawable's bounds
     */
@@ -163,11 +168,21 @@ public abstract class Drawable {
     * object may be the same object stored in the drawable (though this is not
     * guaranteed), so if a persistent copy of the bounds is needed, call
     * copyBounds(rect) instead.
     * You should also not change the object returned by this method as it may
     * be the same object stored in the drawable.
     *
     * @return The bounds of the drawable (which may change later, so caller
     *         beware).
     *         beware). DO NOT ALTER the returned object as it may change the
     *         stored bounds of this drawable.
     *
     * @see #copyBounds()
     * @see #copyBounds(android.graphics.Rect) 
     */
    public final Rect getBounds() {
        if (mBounds == ZERO_BOUNDS_RECT) {
            mBounds = new Rect();
        }

        return mBounds;
    }