Avoid extra splitting/joining.
We know the exact number of arguments, so we don't need to split and
join paths that contain ':'.
Bug: 151076202
Test: atest --test-mapping packages/providers/MediaProvider
Change-Id: I91558bdad0042445f1b85f11d9ea8733f8a930cf
diff --git a/src/com/android/providers/media/DatabaseHelper.java b/src/com/android/providers/media/DatabaseHelper.java
index afa3d63..8967629 100644
--- a/src/com/android/providers/media/DatabaseHelper.java
+++ b/src/com/android/providers/media/DatabaseHelper.java
@@ -69,7 +69,6 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.Set;
@@ -242,7 +241,7 @@
db.setCustomScalarFunction("_INSERT", (arg) -> {
if (arg != null && mFilesListener != null
&& !mSchemaLock.isWriteLockedByCurrentThread()) {
- final String[] split = arg.split(":");
+ final String[] split = arg.split(":", 4);
final String volumeName = split[0];
final long id = Long.parseLong(split[1]);
final int mediaType = Integer.parseInt(split[2]);
@@ -261,7 +260,7 @@
db.setCustomScalarFunction("_UPDATE", (arg) -> {
if (arg != null && mFilesListener != null
&& !mSchemaLock.isWriteLockedByCurrentThread()) {
- final String[] split = arg.split(":");
+ final String[] split = arg.split(":", 10);
final String volumeName = split[0];
final long oldId = Long.parseLong(split[1]);
final int oldMediaType = Integer.parseInt(split[2]);
@@ -271,8 +270,7 @@
final boolean newIsDownload = Integer.parseInt(split[6]) != 0;
final String oldOwnerPackage = split[7];
final String newOwnerPackage = split[8];
- // Path can include ':', assume rest of split[9..length] is path.
- final String oldPath = String.join(":", Arrays.copyOfRange(split, 9, split.length));
+ final String oldPath = split[9];
Trace.beginSection("_UPDATE");
try {
@@ -288,14 +286,13 @@
db.setCustomScalarFunction("_DELETE", (arg) -> {
if (arg != null && mFilesListener != null
&& !mSchemaLock.isWriteLockedByCurrentThread()) {
- final String[] split = arg.split(":");
+ final String[] split = arg.split(":", 6);
final String volumeName = split[0];
final long id = Long.parseLong(split[1]);
final int mediaType = Integer.parseInt(split[2]);
final boolean isDownload = Integer.parseInt(split[3]) != 0;
final String ownerPackage = split[4];
- // Path can include ':', assume rest of split[5..length] is path.
- final String path = String.join(":", Arrays.copyOfRange(split, 5, split.length));
+ final String path = split[5];
Trace.beginSection("_DELETE");
try {