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

Commit 08735185 authored by Chet Haase's avatar Chet Haase
Browse files

Use ArrayMap instead of HashMap in transitions

The new ArrayMap class is more efficient for small collections.
Transitions use maps all over the place to collect/use property
values in setting up the transition animations. Changing to ArrayMap
should be more efficient, especially in terms of memory allocations
and GCs.

Issue #9276256 Transitions: Reduce memory allocations

Change-Id: I07b7d4ba68d5a207808eca11943aa3578fa90e3e
parent aca7d39d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -28310,7 +28310,7 @@ package android.view.transition {
  public class TransitionValues {
    ctor public TransitionValues();
    field public final java.util.HashMap values;
    field public final java.util.Map values;
    field public android.view.View view;
  }
+10 −0
Original line number Diff line number Diff line
@@ -206,6 +206,16 @@ public final class ArrayMap<K, V> implements Map<K, V> {
        }
        mSize = 0;
    }
    /**
     * Create a new ArrayMap with the mappings from the given ArrayMap.
     */
    public ArrayMap(ArrayMap map) {
        this();
        if (map != null) {
            putAll(map);
        }
    }


    /**
     * Make the array map empty.  All storage is released.
+6 −5
Original line number Diff line number Diff line
@@ -26,13 +26,14 @@ import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.ArrayMap;
import android.util.Log;
import android.view.SurfaceView;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;

import java.util.HashMap;
import java.util.Map;

/**
 * This transition captures bitmap representations of target views before and
@@ -60,8 +61,8 @@ public class Crossfade extends Transition {
            return false;
        }
        final View view = startValues.view;
        HashMap<String, Object> startVals = startValues.values;
        HashMap<String, Object> endVals = endValues.values;
        Map<String, Object> startVals = startValues.values;
        Map<String, Object> endVals = endValues.values;
        Bitmap startBitmap = (Bitmap) startVals.get(PROPNAME_BITMAP);
        Bitmap endBitmap = (Bitmap) endVals.get(PROPNAME_BITMAP);
        Drawable startDrawable = (Drawable) startVals.get(PROPNAME_DRAWABLE);
@@ -85,8 +86,8 @@ public class Crossfade extends Transition {
        if (startValues == null || endValues == null) {
            return null;
        }
        HashMap<String, Object> startVals = startValues.values;
        HashMap<String, Object> endVals = endValues.values;
        Map<String, Object> startVals = startValues.values;
        Map<String, Object> endVals = endValues.values;

        final View view = endValues.view;
        Rect startBounds = (Rect) startVals.get(PROPNAME_BOUNDS);
+4 −3
Original line number Diff line number Diff line
@@ -24,11 +24,12 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.util.ArrayMap;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import java.util.HashMap;
import java.util.Map;

/**
 * This transition captures the layout bounds of target views before and after
@@ -216,8 +217,8 @@ public class Move extends Transition {
        if (startValues == null || endValues == null) {
            return false;
        }
        HashMap<String, Object> startParentVals = startValues.values;
        HashMap<String, Object> endParentVals = endValues.values;
        Map<String, Object> startParentVals = startValues.values;
        Map<String, Object> endParentVals = endValues.values;
        ViewGroup startParent = (ViewGroup) startParentVals.get(PROPNAME_PARENT);
        ViewGroup endParent = (ViewGroup) endParentVals.get(PROPNAME_PARENT);
        if (startParent == null || endParent == null) {
+4 −3
Original line number Diff line number Diff line
@@ -20,11 +20,12 @@ import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.util.ArrayMap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.HashMap;
import java.util.Map;

/**
 * This transition tracks changes during scene changes to the
@@ -86,8 +87,8 @@ public class Recolor extends Transition {
        }
        ObjectAnimator anim = null;
        final View view = endValues.view;
        HashMap<String, Object> startVals = startValues.values;
        HashMap<String, Object> endVals = endValues.values;
        Map<String, Object> startVals = startValues.values;
        Map<String, Object> endVals = endValues.values;
        Drawable startBackground = (Drawable) startVals.get(PROPNAME_BACKGROUND);
        Drawable endBackground = (Drawable) endVals.get(PROPNAME_BACKGROUND);
        if (startBackground instanceof ColorDrawable && endBackground instanceof ColorDrawable) {
Loading