Avoid JSON deserialization in common, trivial cases

Signed-off-by: Dariusz Olszewski <starypatyk@users.noreply.github.com>
This commit is contained in:
Dariusz Olszewski 2023-01-07 23:33:31 +01:00 committed by Álvaro Brey (Rebase PR Action)
parent 20c22eb448
commit eae9ff15c7

View file

@ -88,7 +88,8 @@ public class FileDataStorageManager {
private static final String EXCEPTION_MSG = "Exception in batch of operations ";
public static final int ROOT_PARENT_ID = 0;
public static final String NULL_STRING = "null";
private static final String JSON_NULL_STRING = "null";
private static final String JSON_EMPTY_ARRAY = "[]";
private final ContentResolver contentResolver;
private final ContentProviderClient contentProviderClient;
@ -931,7 +932,10 @@ public class FileDataStorageManager {
ocFile.setLockToken(fileEntity.getLockToken());
String sharees = fileEntity.getSharees();
if (sharees == null || NULL_STRING.equals(sharees) || sharees.isEmpty()) {
// Surprisingly JSON deserialization causes significant overhead.
// Avoid it in common, trivial cases (null/empty).
if (sharees == null || sharees.isEmpty() ||
JSON_NULL_STRING.equals(sharees) || JSON_EMPTY_ARRAY.equals(sharees)) {
ocFile.setSharees(new ArrayList<>());
} else {
try {
@ -944,11 +948,19 @@ public class FileDataStorageManager {
}
String metadataSize = fileEntity.getMetadataSize();
ImageDimension imageDimension = gson.fromJson(metadataSize, ImageDimension.class);
if (imageDimension != null) {
ocFile.setImageDimension(imageDimension);
// Surprisingly JSON deserialization causes significant overhead.
// Avoid it in common, trivial cases (null/empty).
if (!(metadataSize == null || metadataSize.isEmpty() || JSON_NULL_STRING.equals(metadataSize))) {
ImageDimension imageDimension = gson.fromJson(metadataSize, ImageDimension.class);
if (imageDimension != null) {
ocFile.setImageDimension(imageDimension);
}
}
// Log_OC.d(TAG, "createFileInstance - fileName: " + fileEntity.getPathDecrypted() +
// " sharees: -->" + (sharees == null ? "<NULL>" : sharees) + "<--" +
// " metadataSize: -->" + (metadataSize == null ? "<NULL>" : metadataSize) + "<--");
return ocFile;
}