Merge "Prefer WeakReference.refersTo() to get()" am: 63e3c2c709
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1956816 Change-Id: I010f99e4de0cb60fecd6b6af38a17e695fc773e8
This commit is contained in:
@@ -119,7 +119,7 @@ class ActivityTransitionState {
|
||||
for (int i = mExitTransitionCoordinators.size() - 1; i >= 0; i--) {
|
||||
WeakReference<ExitTransitionCoordinator> oldRef
|
||||
= mExitTransitionCoordinators.valueAt(i);
|
||||
if (oldRef.get() == null) {
|
||||
if (oldRef.refersTo(null)) {
|
||||
mExitTransitionCoordinators.removeAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -678,8 +678,7 @@ public class ResourcesManager {
|
||||
int refCount = mResourceImpls.size();
|
||||
for (int i = 0; i < refCount; i++) {
|
||||
WeakReference<ResourcesImpl> weakImplRef = mResourceImpls.valueAt(i);
|
||||
ResourcesImpl impl = weakImplRef != null ? weakImplRef.get() : null;
|
||||
if (resourceImpl == impl) {
|
||||
if (weakImplRef != null && weakImplRef.refersTo(resourceImpl)) {
|
||||
return mResourceImpls.keyAt(i);
|
||||
}
|
||||
}
|
||||
@@ -1671,7 +1670,7 @@ public class ResourcesManager {
|
||||
for (int i = mResourceImpls.size() - 1; i >= 0; i--) {
|
||||
final ResourcesKey key = mResourceImpls.keyAt(i);
|
||||
final WeakReference<ResourcesImpl> impl = mResourceImpls.valueAt(i);
|
||||
if (impl == null || impl.get() == null
|
||||
if (impl == null || impl.refersTo(null)
|
||||
|| !ArrayUtils.contains(key.mLoaders, loader)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ public class ColorStateList extends ComplexColor implements Parcelable {
|
||||
// Prune the cache before adding new items.
|
||||
final int N = sCache.size();
|
||||
for (int i = N - 1; i >= 0; i--) {
|
||||
if (sCache.valueAt(i).get() == null) {
|
||||
if (sCache.valueAt(i).refersTo(null)) {
|
||||
sCache.removeAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2011,7 +2011,7 @@ public class Resources {
|
||||
|
||||
// Clean up references to garbage collected themes
|
||||
if (mThemeRefs.size() > mThemeRefsNextFlushSize) {
|
||||
mThemeRefs.removeIf(ref -> ref.get() == null);
|
||||
mThemeRefs.removeIf(ref -> ref.refersTo(null));
|
||||
mThemeRefsNextFlushSize = Math.max(MIN_THEME_REFS_FLUSH_SIZE,
|
||||
2 * mThemeRefs.size());
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ public class ResourcesLoader {
|
||||
|
||||
for (int i = mChangeCallbacks.size() - 1; i >= 0; i--) {
|
||||
final WeakReference<Object> key = mChangeCallbacks.keyAt(i);
|
||||
if (key.get() == null) {
|
||||
if (key.refersTo(null)) {
|
||||
mChangeCallbacks.removeAt(i);
|
||||
} else {
|
||||
uniqueCallbacks.add(mChangeCallbacks.valueAt(i));
|
||||
|
||||
@@ -116,7 +116,7 @@ public final class BinderProxy implements IBinder {
|
||||
for (ArrayList<WeakReference<BinderProxy>> a : mMainIndexValues) {
|
||||
if (a != null) {
|
||||
for (WeakReference<BinderProxy> ref : a) {
|
||||
if (ref.get() != null) {
|
||||
if (!ref.refersTo(null)) {
|
||||
++size;
|
||||
}
|
||||
}
|
||||
@@ -187,7 +187,7 @@ public final class BinderProxy implements IBinder {
|
||||
// This ensures that ArrayList size is bounded by the maximum occupancy of
|
||||
// that bucket.
|
||||
for (int i = 0; i < size; ++i) {
|
||||
if (valueArray.get(i).get() == null) {
|
||||
if (valueArray.get(i).refersTo(null)) {
|
||||
valueArray.set(i, newWr);
|
||||
Long[] keyArray = mMainIndexKeys[myHash];
|
||||
keyArray[i] = key;
|
||||
@@ -195,7 +195,7 @@ public final class BinderProxy implements IBinder {
|
||||
// "Randomly" check one of the remaining entries in [i+1, size), so that
|
||||
// needlessly long buckets are eventually pruned.
|
||||
int rnd = Math.floorMod(++mRandom, size - (i + 1));
|
||||
if (valueArray.get(i + 1 + rnd).get() == null) {
|
||||
if (valueArray.get(i + 1 + rnd).refersTo(null)) {
|
||||
remove(myHash, i + 1 + rnd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -306,7 +306,7 @@ public class TextKeyListener extends BaseKeyListener implements SpanWatcher {
|
||||
|
||||
/* package */ int getPrefs(Context context) {
|
||||
synchronized (this) {
|
||||
if (!mPrefsInited || mResolver.get() == null) {
|
||||
if (!mPrefsInited || mResolver.refersTo(null)) {
|
||||
initPrefs(context);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user