diff options
author | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-26 01:57:30 +0000 |
---|---|---|
committer | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-26 01:57:30 +0000 |
commit | df2ec6fc3e05f74a408b7a7153452cd64cb36c78 (patch) | |
tree | 3a2ddb9a99ae4232ede3a58bb54eab7399175e31 /base/android | |
parent | 24a6fef8e89b844d9eca9d99305161991a4d2bac (diff) | |
download | chromium_src-df2ec6fc3e05f74a408b7a7153452cd64cb36c78.zip chromium_src-df2ec6fc3e05f74a408b7a7153452cd64cb36c78.tar.gz chromium_src-df2ec6fc3e05f74a408b7a7153452cd64cb36c78.tar.bz2 |
Reduce number of temporory objects created posting tasks
Gives the GC a little less work todo, especially during repeatedly called async callpaths.
Review URL: https://chromiumcodereview.appspot.com/10913284
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@158713 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/android')
-rw-r--r-- | base/android/java/src/org/chromium/base/ThreadUtils.java | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/base/android/java/src/org/chromium/base/ThreadUtils.java b/base/android/java/src/org/chromium/base/ThreadUtils.java index ca31c3d..b827a0b 100644 --- a/base/android/java/src/org/chromium/base/ThreadUtils.java +++ b/base/android/java/src/org/chromium/base/ThreadUtils.java @@ -103,7 +103,11 @@ public class ThreadUtils { * @param r The Runnable to run */ public static void runOnUiThread(Runnable r) { - runOnUiThread(new FutureTask<Void>(r, null)); + if (runningOnUiThread()) { + r.run(); + } else { + LazyHolder.sUiThreadHandler.post(r); + } } /** @@ -114,7 +118,7 @@ public class ThreadUtils { * @return The queried task (to aid inline construction) */ public static <T> FutureTask<T> postOnUiThread(FutureTask<T> task) { - new Handler(Looper.getMainLooper()).post(task); + LazyHolder.sUiThreadHandler.post(task); return task; } @@ -131,4 +135,8 @@ public class ThreadUtils { public static boolean runningOnUiThread() { return Looper.getMainLooper() == Looper.myLooper(); } + + private static class LazyHolder { + private static Handler sUiThreadHandler = new Handler(Looper.getMainLooper()); + } } |