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

Commit 7eee509d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Optimizing TimeSparseArray#put in case of collisions" into pi-dev

parents ebd87bf3 a2cf00a0
Loading
Loading
Loading
Loading
+11 −6
Original line number Original line Diff line number Diff line
@@ -81,13 +81,18 @@ public class TimeSparseArray<E> extends LongSparseArray<E> {
    @Override
    @Override
    public void put(long key, E value) {
    public void put(long key, E value) {
        final long origKey = key;
        final long origKey = key;
        while (indexOfKey(key) >= 0) {
        int keyIndex = indexOfKey(key);
        if (keyIndex >= 0) {
            final long sz = size();
            while (keyIndex < sz && keyAt(keyIndex) == key) {
                key++;
                key++;
                keyIndex++;
            }
            }
        if (origKey != key) {
            if (key >= origKey + 10) {
                Slog.w(TAG, "Value " + value + " supposed to be inserted at " + origKey
                Slog.w(TAG, "Value " + value + " supposed to be inserted at " + origKey
                        + " displaced to " + key);
                        + " displaced to " + key);
            }
            }
        }
        super.put(key, value);
        super.put(key, value);
    }
    }