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

Commit e10a3513 authored by Robert Horvath's avatar Robert Horvath
Browse files

Prevent ArrayList allocation for prefer keep clear areas

This avoids creating an ArrayList if there are no keep clear areas,
returning early with an empty or singleton list where possible.

Bug: 222567277
Test: android.view.ViewShowHidePerfTest#testVisibleToInvisible
Change-Id: Id718a37ea8aa4fcf4edbaade532cea826b15adf0
parent e0934dad
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -11939,13 +11939,22 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    @NonNull
    List<Rect> collectPreferKeepClearRects() {
        ListenerInfo info = mListenerInfo;
        final List<Rect> list = new ArrayList<>();
        boolean keepBoundsClear =
                (info != null && info.mPreferKeepClear) || mPreferKeepClearForFocus;
        boolean hasCustomKeepClearRects = info != null && info.mKeepClearRects != null;
        if (!keepBoundsClear && !hasCustomKeepClearRects) {
            return Collections.emptyList();
        } else if (keepBoundsClear && !hasCustomKeepClearRects) {
            return Collections.singletonList(new Rect(0, 0, getWidth(), getHeight()));
        }
        if ((info != null && info.mPreferKeepClear) || mPreferKeepClearForFocus) {
        final List<Rect> list = new ArrayList<>();
        if (keepBoundsClear) {
            list.add(new Rect(0, 0, getWidth(), getHeight()));
        }
        if (info != null && info.mKeepClearRects != null) {
        if (hasCustomKeepClearRects) {
            list.addAll(info.mKeepClearRects);
        }