summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@google.com>2018-07-27 20:16:40 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-07-27 20:16:40 +0000
commitb4cd7588cd7e9b4541be7b79ce2fb3bebfead15d (patch)
treea44528e1a77a197f4f0d65662ca434d918bc7a87 /core/java/android
parent2c813a2fbe5b82247294637bdb77a152035392e4 (diff)
parent42122bfecfc5efba843726f88ecc8e24adf3eabc (diff)
Merge "Bind update() args as Object[] for performance."
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/database/sqlite/SQLiteQueryBuilder.java21
1 files changed, 12 insertions, 9 deletions
diff --git a/core/java/android/database/sqlite/SQLiteQueryBuilder.java b/core/java/android/database/sqlite/SQLiteQueryBuilder.java
index 2d45b14146fc..3298140b4a9b 100644
--- a/core/java/android/database/sqlite/SQLiteQueryBuilder.java
+++ b/core/java/android/database/sqlite/SQLiteQueryBuilder.java
@@ -29,7 +29,7 @@ import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Log;
-import com.android.internal.util.ArrayUtils;
+import libcore.util.EmptyArray;
import java.util.Arrays;
import java.util.Iterator;
@@ -436,7 +436,6 @@ public class SQLiteQueryBuilder
* that they appear in the selection. The values will be bound
* as Strings.
* @return the number of rows updated
- * @hide
*/
public int update(@NonNull SQLiteDatabase db, @NonNull ContentValues values,
@Nullable String selection, @Nullable String[] selectionArgs) {
@@ -471,14 +470,19 @@ public class SQLiteQueryBuilder
sql = unwrappedSql;
}
+ if (selectionArgs == null) {
+ selectionArgs = EmptyArray.STRING;
+ }
final ArrayMap<String, Object> rawValues = values.getValues();
- final String[] updateArgs = new String[rawValues.size()];
- for (int i = 0; i < updateArgs.length; i++) {
- final Object arg = rawValues.valueAt(i);
- updateArgs[i] = (arg != null) ? arg.toString() : null;
+ final int valuesLength = rawValues.size();
+ final Object[] sqlArgs = new Object[valuesLength + selectionArgs.length];
+ for (int i = 0; i < sqlArgs.length; i++) {
+ if (i < valuesLength) {
+ sqlArgs[i] = rawValues.valueAt(i);
+ } else {
+ sqlArgs[i] = selectionArgs[i - valuesLength];
+ }
}
-
- final String[] sqlArgs = ArrayUtils.concat(String.class, updateArgs, selectionArgs);
if (Log.isLoggable(TAG, Log.DEBUG)) {
if (Build.IS_DEBUGGABLE) {
Log.d(TAG, sql + " with args " + Arrays.toString(sqlArgs));
@@ -502,7 +506,6 @@ public class SQLiteQueryBuilder
* that they appear in the selection. The values will be bound
* as Strings.
* @return the number of rows deleted
- * @hide
*/
public int delete(@NonNull SQLiteDatabase db, @Nullable String selection,
@Nullable String[] selectionArgs) {