Merge "Reduce Integer allocations in ThreadLocalWorkSource" am: c208284b94 am: a7250e536f
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2361769
Change-Id: Ie772df75cfb6a947a975735f32de925f0f9d30d6
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/core/java/android/os/ThreadLocalWorkSource.java b/core/java/android/os/ThreadLocalWorkSource.java
index 894b1cc4..e9adb20 100644
--- a/core/java/android/os/ThreadLocalWorkSource.java
+++ b/core/java/android/os/ThreadLocalWorkSource.java
@@ -39,8 +39,8 @@
*/
public final class ThreadLocalWorkSource {
public static final int UID_NONE = Message.UID_NONE;
- private static final ThreadLocal<Integer> sWorkSourceUid =
- ThreadLocal.withInitial(() -> UID_NONE);
+ private static final ThreadLocal<int []> sWorkSourceUid =
+ ThreadLocal.withInitial(() -> new int[] {UID_NONE});
/**
* Returns the UID to blame for the code currently executed on this thread.
@@ -50,7 +50,7 @@
* <p>It can also be set manually using {@link #setUid(int)}.
*/
public static int getUid() {
- return sWorkSourceUid.get();
+ return sWorkSourceUid.get()[0];
}
/**
@@ -65,7 +65,7 @@
*/
public static long setUid(int uid) {
final long token = getToken();
- sWorkSourceUid.set(uid);
+ sWorkSourceUid.get()[0] = uid;
return token;
}
@@ -73,7 +73,7 @@
* Restores the state using the provided token.
*/
public static void restore(long token) {
- sWorkSourceUid.set(parseUidFromToken(token));
+ sWorkSourceUid.get()[0] = parseUidFromToken(token);
}
/**
@@ -88,7 +88,7 @@
* </pre>
*
* @return a token that can be used to restore the state.
- **/
+ */
public static long clear() {
return setUid(UID_NONE);
}
@@ -98,7 +98,7 @@
}
private static long getToken() {
- return sWorkSourceUid.get();
+ return sWorkSourceUid.get()[0];
}
private ThreadLocalWorkSource() {