am a206efcf
: Merge "android.os.Message: respect sPoolSize"
* commit 'a206efcf8d2e56cbd0d1de125b29b45fc6cc8431': android.os.Message: respect sPoolSize
This commit is contained in:
@ -85,9 +85,9 @@ public final class Message implements Parcelable {
|
|||||||
// sometimes we store linked lists of these things
|
// sometimes we store linked lists of these things
|
||||||
/*package*/ Message next;
|
/*package*/ Message next;
|
||||||
|
|
||||||
private static Object mPoolSync = new Object();
|
private static final Object sPoolSync = new Object();
|
||||||
private static Message mPool;
|
private static Message sPool;
|
||||||
private static int mPoolSize = 0;
|
private static int sPoolSize = 0;
|
||||||
|
|
||||||
private static final int MAX_POOL_SIZE = 10;
|
private static final int MAX_POOL_SIZE = 10;
|
||||||
|
|
||||||
@ -96,11 +96,12 @@ public final class Message implements Parcelable {
|
|||||||
* avoid allocating new objects in many cases.
|
* avoid allocating new objects in many cases.
|
||||||
*/
|
*/
|
||||||
public static Message obtain() {
|
public static Message obtain() {
|
||||||
synchronized (mPoolSync) {
|
synchronized (sPoolSync) {
|
||||||
if (mPool != null) {
|
if (sPool != null) {
|
||||||
Message m = mPool;
|
Message m = sPool;
|
||||||
mPool = m.next;
|
sPool = m.next;
|
||||||
m.next = null;
|
m.next = null;
|
||||||
|
sPoolSize--;
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -237,12 +238,12 @@ public final class Message implements Parcelable {
|
|||||||
* freed.
|
* freed.
|
||||||
*/
|
*/
|
||||||
public void recycle() {
|
public void recycle() {
|
||||||
synchronized (mPoolSync) {
|
synchronized (sPoolSync) {
|
||||||
if (mPoolSize < MAX_POOL_SIZE) {
|
if (sPoolSize < MAX_POOL_SIZE) {
|
||||||
clearForRecycle();
|
clearForRecycle();
|
||||||
|
next = sPool;
|
||||||
next = mPool;
|
sPool = this;
|
||||||
mPool = this;
|
sPoolSize++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -453,4 +454,3 @@ public final class Message implements Parcelable {
|
|||||||
replyTo = Messenger.readMessengerOrNullFromParcel(source);
|
replyTo = Messenger.readMessengerOrNullFromParcel(source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user