diff options
| author | Jeff Sharkey <jsharkey@android.com> | 2018-07-26 09:39:18 -0600 |
|---|---|---|
| committer | Jeff Sharkey <jsharkey@android.com> | 2018-07-26 10:49:53 -0600 |
| commit | 42122bfecfc5efba843726f88ecc8e24adf3eabc (patch) | |
| tree | db0dec64cf827e00787fb1432b17589ef460bcad /core/java/android | |
| parent | 13b3a907ba5df3c077e4ec1e0b017dc8af078a62 (diff) | |
Bind update() args as Object[] for performance.
It's wasteful to convert them to String when SQLite already knows
how to bind specific data types, including funky types like byte[].
Also promote to public API, since they're generally useful.
Bug: 111085900
Test: atest packages/providers/DownloadProvider/tests/
Test: atest cts/tests/app/src/android/app/cts/DownloadManagerTest.java
Test: atest cts/tests/tests/database/src/android/database/sqlite/cts/SQLiteQueryBuilderTest.java
Change-Id: I5b418bca1204773fd2795156a2f47906ca1e1a6b
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/database/sqlite/SQLiteQueryBuilder.java | 21 |
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) { |
