OSDN Git Service

Return early when checking divider before child zero.
authorJake Wharton <jakewharton@gmail.com>
Sun, 29 Jul 2012 04:31:51 +0000 (21:31 -0700)
committerJake Wharton <jakewharton@gmail.com>
Sun, 29 Jul 2012 04:40:04 +0000 (21:40 -0700)
Previously the `getChildAt` method would be called with an index of -1 which
would lead to an exception being thrown and caught. This is unnecessary since
we know there will never be a divider before the first child. It also avoids
additional object creation since this method can be invoked quite frequently.

Change-Id: Iab44520d5d52f96a829a009cdd1201696edbf9a4

core/java/com/android/internal/view/menu/ActionMenuView.java

index f54575b..cef6a8f 100644 (file)
@@ -524,6 +524,9 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo
 
     @Override
     protected boolean hasDividerBeforeChildAt(int childIndex) {
+        if (childIndex == 0) {
+            return false;
+        }
         final View childBefore = getChildAt(childIndex - 1);
         final View child = getChildAt(childIndex);
         boolean result = false;