Use SparseArray for detached views.

Summary:
This is minor, but for our use case a SparseArray is going to be faster as long as we have less than 10,000 clipped subviews, and will also use much less memory.

Faster because of the boxing, unboxing and hash caching; less memory as it is two arrays instead of the object overhead of the HashMap.

Reviewed By: ahmedre

Differential Revision: D3704326
This commit is contained in:
Seth Kirby
2016-08-15 20:39:50 -07:00
committed by Ahmed El-Helw
parent b2f41e2921
commit a602891946
4 changed files with 14 additions and 10 deletions

View File

@@ -163,7 +163,7 @@ import com.facebook.react.views.view.ReactClippingViewGroupHelper;
// less in our case because of the large constant overhead and auto boxing of the map.
private SparseIntArray mDrawViewIndexMap = StateBuilder.EMPTY_SPARSE_INT;
// Map of views that are currently clipped.
private final Map<Integer, View> mClippedSubviews = new HashMap<>();
private final SparseArray<View> mClippedSubviews = new SparseArray<>();
protected final Rect mClippingRect = new Rect();
@@ -297,11 +297,11 @@ import com.facebook.react.views.view.ReactClippingViewGroupHelper;
}
private boolean isClipped(int id) {
return mClippedSubviews.containsKey(id);
return mClippedSubviews.get(id) != null;
}
private boolean isNotClipped(int id) {
return !mClippedSubviews.containsKey(id);
return mClippedSubviews.get(id) == null;
}
@Override
@@ -510,8 +510,8 @@ import com.facebook.react.views.view.ReactClippingViewGroupHelper;
}
@Override
public Collection<View> getDetachedViews() {
return mClippedSubviews.values();
public SparseArray<View> getDetachedViews() {
return mClippedSubviews;
}
/**