OSDN Git Service

Remove unnecessary lock to save 1 allocation per TextView
authorRomain Guy <romainguy@google.com>
Mon, 3 Jun 2013 21:19:54 +0000 (14:19 -0700)
committerRomain Guy <romainguy@google.com>
Mon, 3 Jun 2013 21:19:54 +0000 (14:19 -0700)
Change-Id: I4fb885c61b44e57b8abaf3beedf61aaab3ef5d71

core/java/android/widget/TextView.java

index b1692d7..4410c2e 100644 (file)
@@ -548,7 +548,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
     private InputFilter[] mFilters = NO_FILTERS;
 
     private volatile Locale mCurrentSpellCheckerLocaleCache;
-    private final ReentrantLock mCurrentTextServicesLocaleLock = new ReentrantLock();
 
     // It is possible to have a selection even when mEditor is null (programmatically set, like when
     // a link is pressed). These highlight-related fields do not go in mEditor.
@@ -8023,16 +8022,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
     }
 
     private void updateTextServicesLocaleAsync() {
+        // AsyncTask.execute() uses a serial executor which means we don't have
+        // to lock around updateTextServicesLocaleLocked() to prevent it from
+        // being executed n times in parallel.
         AsyncTask.execute(new Runnable() {
             @Override
             public void run() {
-                if (mCurrentTextServicesLocaleLock.tryLock()) {
-                    try {
-                        updateTextServicesLocaleLocked();
-                    } finally {
-                        mCurrentTextServicesLocaleLock.unlock();
-                    }
-                }
+                updateTextServicesLocaleLocked();
             }
         });
     }