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
This commit is contained in:
@@ -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 ((info != null && info.mPreferKeepClear) || mPreferKeepClearForFocus) {
|
||||
if (!keepBoundsClear && !hasCustomKeepClearRects) {
|
||||
return Collections.emptyList();
|
||||
} else if (keepBoundsClear && !hasCustomKeepClearRects) {
|
||||
return Collections.singletonList(new Rect(0, 0, getWidth(), getHeight()));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user