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

Commit 795766d0 authored by Robin Lee's avatar Robin Lee
Browse files

Avoid saving result from WeakHashMap.size()

This value is only valid until the next call on the hash
map because it can garbage collect before anything that
resizes or accesses the backing table

Bug: 266978825
Change-Id: I8c8e2df8c205130da0d3831b88450cc2534f97bb
parent 39169f81
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -62,7 +62,6 @@ public class SurfaceControlRegistry {
    private static class DefaultReporter implements Reporter {
        public void onMaxLayersExceeded(WeakHashMap<SurfaceControl, Long> surfaceControls,
                int limit, PrintWriter pw) {
            final int size = Math.min(surfaceControls.size(), limit);
            final long now = SystemClock.elapsedRealtime();
            final ArrayList<Map.Entry<SurfaceControl, Long>> entries = new ArrayList<>();
            for (Map.Entry<SurfaceControl, Long> entry : surfaceControls.entrySet()) {
@@ -71,6 +70,7 @@ public class SurfaceControlRegistry {
            // Sort entries by time registered when dumping
            // TODO: Or should it sort by name?
            entries.sort((o1, o2) -> (int) (o1.getValue() - o2.getValue()));
            final int size = Math.min(entries.size(), limit);

            pw.println("SurfaceControlRegistry");
            pw.println("----------------------");