am 6ba5f0d3: Merge "Add error log to expensive ArraysCompatUtils.binarySearch"

* commit '6ba5f0d341a0fef9020c9dee814fb4b369620737':
  Add error log to expensive ArraysCompatUtils.binarySearch
main
Tadashi G. Takaoka 2011-12-15 22:56:18 -08:00 committed by Android Git Automerger
commit b7f60b4ca3
1 changed files with 13 additions and 2 deletions

View File

@ -16,10 +16,14 @@
package com.android.inputmethod.compat; package com.android.inputmethod.compat;
import android.util.Log;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Arrays; import java.util.Arrays;
public class ArraysCompatUtils { public class ArraysCompatUtils {
private static final String TAG = ArraysCompatUtils.class.getSimpleName();
private static final Method METHOD_Arrays_binarySearch = CompatUtils private static final Method METHOD_Arrays_binarySearch = CompatUtils
.getMethod(Arrays.class, "binarySearch", int[].class, int.class, int.class, int.class); .getMethod(Arrays.class, "binarySearch", int[].class, int.class, int.class, int.class);
@ -33,8 +37,15 @@ public class ArraysCompatUtils {
} }
} }
/* package */ static int compatBinarySearch(int[] array, int startIndex, int endIndex, // TODO: Implement fast binary search
int value) { /* package for testing */
static int compatBinarySearch(int[] array, int startIndex, int endIndex, int value) {
// Output error log because this method has strict performance penalty.
// Note that this method has been called only from spell checker and spell checker exists
// only from IceCreamSandwich and after, so that there is no chance on pre-ICS device to
// invoke this method.
Log.e(TAG, "Invoked expensive binarySearch");
if (startIndex > endIndex) throw new IllegalArgumentException(); if (startIndex > endIndex) throw new IllegalArgumentException();
if (startIndex < 0 || endIndex > array.length) throw new ArrayIndexOutOfBoundsException(); if (startIndex < 0 || endIndex > array.length) throw new ArrayIndexOutOfBoundsException();