diff options
| author | 2022-12-06 13:10:01 +0000 | |
|---|---|---|
| committer | 2022-12-06 13:10:01 +0000 | |
| commit | 91824e804fd84a5d1ed0a1093e98058368de856c (patch) | |
| tree | cf2c0e755d2d26257b243e48841ee4f8869867c5 | |
| parent | 3f1be476273f47eeb2a7233b8a5389992158fe93 (diff) | |
| parent | 740710388b1a759a12938ad6ab9706bdf8723c81 (diff) | |
Merge "Change contentEquals implementation to operate in O(n) time."
| -rw-r--r-- | core/java/android/util/SparseArray.java | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/core/java/android/util/SparseArray.java b/core/java/android/util/SparseArray.java index 05c8617294da..cc83decc7b21 100644 --- a/core/java/android/util/SparseArray.java +++ b/core/java/android/util/SparseArray.java @@ -525,9 +525,10 @@ public class SparseArray<E> implements Cloneable { return false; } + // size() calls above took care about gc() compaction. for (int index = 0; index < size; index++) { - int key = keyAt(index); - if (!Objects.equals(valueAt(index), other.get(key))) { + if (mKeys[index] != other.mKeys[index] + || !Objects.equals(mValues[index], other.mValues[index])) { return false; } } @@ -545,10 +546,11 @@ public class SparseArray<E> implements Cloneable { public int contentHashCode() { int hash = 0; int size = size(); + // size() call above took care about gc() compaction. for (int index = 0; index < size; index++) { - int key = keyAt(index); - E value = valueAt(index); - hash = 31 * hash + Objects.hashCode(key); + int key = mKeys[index]; + E value = (E) mValues[index]; + hash = 31 * hash + key; hash = 31 * hash + Objects.hashCode(value); } return hash; |