codacy: Avoid instantiating new objects inside loops

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2019-08-27 12:20:34 +02:00
parent fc156a72bc
commit dfc1a5e89f
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B

View file

@ -683,6 +683,7 @@ public class FileDataStorageManager {
if (c.moveToFirst()) { if (c.moveToFirst()) {
int lengthOfOldPath = file.getRemotePath().length(); int lengthOfOldPath = file.getRemotePath().length();
int lengthOfOldStoragePath = defaultSavePath.length() + lengthOfOldPath; int lengthOfOldStoragePath = defaultSavePath.length() + lengthOfOldPath;
String[] fileId = new String[1];
do { do {
ContentValues cv = new ContentValues(); // keep construction in the loop ContentValues cv = new ContentValues(); // keep construction in the loop
OCFile child = createFileInstance(c); OCFile child = createFileInstance(c);
@ -704,13 +705,11 @@ public class FileDataStorageManager {
if (child.getRemotePath().equals(file.getRemotePath())) { if (child.getRemotePath().equals(file.getRemotePath())) {
cv.put(ProviderTableMeta.FILE_PARENT, targetParent.getFileId()); cv.put(ProviderTableMeta.FILE_PARENT, targetParent.getFileId());
} }
fileId[0] = String.valueOf(child.getFileId());
operations.add( operations.add(
ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI). ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
withValues(cv). withValues(cv).
withSelection( withSelection(ProviderTableMeta._ID + "=?", fileId)
ProviderTableMeta._ID + "=?",
new String[]{String.valueOf(child.getFileId())}
)
.build()); .build());
} while (c.moveToNext()); } while (c.moveToNext());
@ -802,9 +801,10 @@ public class FileDataStorageManager {
ArrayList<ContentProviderOperation> operations = new ArrayList<>(cursor.getCount()); ArrayList<ContentProviderOperation> operations = new ArrayList<>(cursor.getCount());
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
String[] fileId = new String[1];
do { do {
ContentValues cv = new ContentValues(); ContentValues cv = new ContentValues();
long fileId = cursor.getLong(cursor.getColumnIndex(ProviderTableMeta._ID)); fileId[0] = String.valueOf(cursor.getLong(cursor.getColumnIndex(ProviderTableMeta._ID)));
String oldFileStoragePath = String oldFileStoragePath =
cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH)); cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH));
@ -815,7 +815,7 @@ public class FileDataStorageManager {
operations.add( operations.add(
ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI). ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
withValues(cv). withValues(cv).
withSelection(ProviderTableMeta._ID + "=?", new String[]{String.valueOf(fileId)}) withSelection(ProviderTableMeta._ID + "=?", fileId)
.build()); .build());
} }
@ -1850,6 +1850,7 @@ public class FileDataStorageManager {
parentPath = parentPath.substring(0, parentPath.lastIndexOf(OCFile.PATH_SEPARATOR) + 1); parentPath = parentPath.substring(0, parentPath.lastIndexOf(OCFile.PATH_SEPARATOR) + 1);
Log_OC.d(TAG, "checking parents to remove conflict; STARTING with " + parentPath); Log_OC.d(TAG, "checking parents to remove conflict; STARTING with " + parentPath);
String[] projection = new String[]{ProviderTableMeta._ID};
while (parentPath.length() > 0) { while (parentPath.length() > 0) {
String whereForDescencentsInConflict = String whereForDescencentsInConflict =
@ -1861,7 +1862,7 @@ public class FileDataStorageManager {
if (getContentResolver() != null) { if (getContentResolver() != null) {
descendentsInConflict = getContentResolver().query( descendentsInConflict = getContentResolver().query(
ProviderTableMeta.CONTENT_URI_FILE, ProviderTableMeta.CONTENT_URI_FILE,
new String[]{ProviderTableMeta._ID}, projection,
whereForDescencentsInConflict, whereForDescencentsInConflict,
new String[]{account.name, parentPath + "%"}, new String[]{account.name, parentPath + "%"},
null null
@ -1870,7 +1871,7 @@ public class FileDataStorageManager {
try { try {
descendentsInConflict = getContentProviderClient().query( descendentsInConflict = getContentProviderClient().query(
ProviderTableMeta.CONTENT_URI_FILE, ProviderTableMeta.CONTENT_URI_FILE,
new String[]{ProviderTableMeta._ID}, projection,
whereForDescencentsInConflict, whereForDescencentsInConflict,
new String[]{account.name, parentPath + "%"}, new String[]{account.name, parentPath + "%"},
null null