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

Commit 04be6f6e authored by Shai Barack's avatar Shai Barack
Browse files

Check if priority queue is empty before attempting to get first element

Avoids allocating an exception that we'll just discard in a common (non-exceptional) case.

Bug: 415954362
Flag: build.RELEASE_PACKAGE_MESSAGEQUEUE_IMPLEMENTATION
Change-Id: I9065f4b50da921f14354f1055cace52f098e55d0
parent b4b83acf
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -2439,6 +2439,13 @@ public final class MessageQueue {
    }

    private static Message first(ConcurrentSkipListSet<Message> queue) {
        // If the queue is empty, avoid calling queue.first() which will allocate
        // an exception that we'll immediately ignore.
        // We might race with another thread that's removing from the queue and
        // end up with the exception anyway, but at least we tried.
        if (queue.isEmpty()) {
            return null;
        }
        try {
            return queue.first();
        } catch (NoSuchElementException e) {