From 825992f503439bc87d9d7e698a487f17b5acc243 Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Sat, 28 Jul 2012 21:31:51 -0700 Subject: [PATCH] Return early when checking divider before child zero. 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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/java/com/android/internal/view/menu/ActionMenuView.java b/core/java/com/android/internal/view/menu/ActionMenuView.java index f54575b827df3..cef6a8f533749 100644 --- a/core/java/com/android/internal/view/menu/ActionMenuView.java +++ b/core/java/com/android/internal/view/menu/ActionMenuView.java @@ -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;