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

Commit 2b0379b7 authored by Orion Hodson's avatar Orion Hodson Committed by Automerger Merge Worker
Browse files

Merge "Reduce Integer allocations in ThreadLocalWorkSource" am: c208284b am: a7250e53

parents 66dd727f a7250e53
Loading
Loading
Loading
Loading
+7 −7
Original line number Original line Diff line number Diff line
@@ -39,8 +39,8 @@ package android.os;
 */
 */
public final class ThreadLocalWorkSource {
public final class ThreadLocalWorkSource {
    public static final int UID_NONE = Message.UID_NONE;
    public static final int UID_NONE = Message.UID_NONE;
    private static final ThreadLocal<Integer> sWorkSourceUid =
    private static final ThreadLocal<int []> sWorkSourceUid =
            ThreadLocal.withInitial(() -> UID_NONE);
            ThreadLocal.withInitial(() -> new int[] {UID_NONE});


    /**
    /**
     * Returns the UID to blame for the code currently executed on this thread.
     * Returns the UID to blame for the code currently executed on this thread.
@@ -50,7 +50,7 @@ public final class ThreadLocalWorkSource {
     * <p>It can also be set manually using {@link #setUid(int)}.
     * <p>It can also be set manually using {@link #setUid(int)}.
     */
     */
    public static int getUid() {
    public static int getUid() {
        return sWorkSourceUid.get();
        return sWorkSourceUid.get()[0];
    }
    }


    /**
    /**
@@ -65,7 +65,7 @@ public final class ThreadLocalWorkSource {
     */
     */
    public static long setUid(int uid) {
    public static long setUid(int uid) {
        final long token = getToken();
        final long token = getToken();
        sWorkSourceUid.set(uid);
        sWorkSourceUid.get()[0] = uid;
        return token;
        return token;
    }
    }


@@ -73,7 +73,7 @@ public final class ThreadLocalWorkSource {
     * Restores the state using the provided token.
     * Restores the state using the provided token.
     */
     */
    public static void restore(long token) {
    public static void restore(long token) {
        sWorkSourceUid.set(parseUidFromToken(token));
        sWorkSourceUid.get()[0] = parseUidFromToken(token);
    }
    }


    /**
    /**
@@ -88,7 +88,7 @@ public final class ThreadLocalWorkSource {
     * </pre>
     * </pre>
     *
     *
     * @return a token that can be used to restore the state.
     * @return a token that can be used to restore the state.
     **/
     */
    public static long clear() {
    public static long clear() {
        return setUid(UID_NONE);
        return setUid(UID_NONE);
    }
    }
@@ -98,7 +98,7 @@ public final class ThreadLocalWorkSource {
    }
    }


    private static long getToken() {
    private static long getToken() {
        return sWorkSourceUid.get();
        return sWorkSourceUid.get()[0];
    }
    }


    private ThreadLocalWorkSource() {
    private ThreadLocalWorkSource() {