Keep lists as unsplit strings
There is no point in splitting the strings ahead of time since 1) not all strings need to be split and 2) we currently deserialize them just as often as we iterate over them.
This commit is contained in:
parent
0513bb2de7
commit
1d025c1e7d
@ -20,6 +20,7 @@
|
|||||||
package org.fdroid.fdroid;
|
package org.fdroid.fdroid;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
@ -35,6 +36,7 @@ import android.database.sqlite.SQLiteOpenHelper;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.text.TextUtils.SimpleStringSplitter;
|
||||||
|
|
||||||
public class DB {
|
public class DB {
|
||||||
|
|
||||||
@ -93,7 +95,7 @@ public class DB {
|
|||||||
|
|
||||||
// Array of anti-features (as defined in the metadata
|
// Array of anti-features (as defined in the metadata
|
||||||
// documentation) or null if there aren't any.
|
// documentation) or null if there aren't any.
|
||||||
public String[] antiFeatures;
|
public CommaSeparatedList antiFeatures;
|
||||||
|
|
||||||
// True if there are new versions (apks) that the user hasn't
|
// True if there are new versions (apks) that the user hasn't
|
||||||
// explicitly ignored. (We're currently not using the database
|
// explicitly ignored. (We're currently not using the database
|
||||||
@ -160,8 +162,8 @@ public class DB {
|
|||||||
public String server;
|
public String server;
|
||||||
public String hash;
|
public String hash;
|
||||||
public int minSdkVersion; // 0 if unknown
|
public int minSdkVersion; // 0 if unknown
|
||||||
public String[] permissions; // null if empty or unknown
|
public CommaSeparatedList permissions; // null if empty or unknown
|
||||||
public String[] features; // null if empty or unknown
|
public CommaSeparatedList features; // null if empty or unknown
|
||||||
|
|
||||||
// ID (md5 sum of public key) of signature. Might be null, in the
|
// ID (md5 sum of public key) of signature. Might be null, in the
|
||||||
// transition to this field existing.
|
// transition to this field existing.
|
||||||
@ -414,7 +416,7 @@ public class DB {
|
|||||||
while (!c.isAfterLast()) {
|
while (!c.isAfterLast()) {
|
||||||
|
|
||||||
App app = new App();
|
App app = new App();
|
||||||
app.antiFeatures = decodeList(c
|
app.antiFeatures = DB.CommaSeparatedList.make(c
|
||||||
.getString(c.getColumnIndex("antiFeatures")));
|
.getString(c.getColumnIndex("antiFeatures")));
|
||||||
boolean include = true;
|
boolean include = true;
|
||||||
if (app.antiFeatures != null) {
|
if (app.antiFeatures != null) {
|
||||||
@ -477,10 +479,10 @@ public class DB {
|
|||||||
.getColumnIndex("apkSource"));
|
.getColumnIndex("apkSource"));
|
||||||
apk.minSdkVersion = c2.getInt(c2
|
apk.minSdkVersion = c2.getInt(c2
|
||||||
.getColumnIndex("minSdkVersion"));
|
.getColumnIndex("minSdkVersion"));
|
||||||
apk.permissions = decodeList(c2.getString(c2
|
apk.permissions = CommaSeparatedList.make(c2
|
||||||
.getColumnIndex("permissions")));
|
.getString(c2.getColumnIndex("permissions")));
|
||||||
apk.features = decodeList(c2.getString(c2
|
apk.features = CommaSeparatedList.make(c2
|
||||||
.getColumnIndex("features")));
|
.getString(c2.getColumnIndex("features")));
|
||||||
app.apks.add(apk);
|
app.apks.add(apk);
|
||||||
if (!compatible && compatChecker.isCompatible(apk)) {
|
if (!compatible && compatChecker.isCompatible(apk)) {
|
||||||
// At least one compatible APK.
|
// At least one compatible APK.
|
||||||
@ -567,23 +569,33 @@ public class DB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join the elements of a String array with commas. An empty array
|
public static class CommaSeparatedList implements Iterable<String> {
|
||||||
// or a null value both result in null as the return value.
|
private String value;
|
||||||
public static String encodeList(String[] array) {
|
|
||||||
if (array == null || array.length == 0)
|
|
||||||
return null;
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (String e : array) {
|
|
||||||
sb.append(e);
|
|
||||||
sb.append(",");
|
|
||||||
}
|
|
||||||
return sb.substring(0, sb.length() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String[] decodeList(String string) {
|
private CommaSeparatedList(String list) {
|
||||||
if (string == null || string.length() == 0)
|
value = list;
|
||||||
return null;
|
}
|
||||||
return string.split(",");
|
|
||||||
|
public static CommaSeparatedList make(String list) {
|
||||||
|
if (list == null || list.length() == 0)
|
||||||
|
return null;
|
||||||
|
else
|
||||||
|
return new CommaSeparatedList(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String str(CommaSeparatedList instance) {
|
||||||
|
return (instance == null ? null : instance.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterator<String> iterator() {
|
||||||
|
SimpleStringSplitter splitter = new SimpleStringSplitter(',');
|
||||||
|
splitter.setString(value);
|
||||||
|
return splitter.iterator();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector<App> updateApps = null;
|
private Vector<App> updateApps = null;
|
||||||
@ -726,7 +738,7 @@ public class DB {
|
|||||||
values.put("installedVerCode", upapp.installedVerCode);
|
values.put("installedVerCode", upapp.installedVerCode);
|
||||||
values.put("marketVersion", upapp.marketVersion);
|
values.put("marketVersion", upapp.marketVersion);
|
||||||
values.put("marketVercode", upapp.marketVercode);
|
values.put("marketVercode", upapp.marketVercode);
|
||||||
values.put("antiFeatures", encodeList(upapp.antiFeatures));
|
values.put("antiFeatures", CommaSeparatedList.str(upapp.antiFeatures));
|
||||||
values.put("hasUpdates", upapp.hasUpdates ? 1 : 0);
|
values.put("hasUpdates", upapp.hasUpdates ? 1 : 0);
|
||||||
if (oldapp != null) {
|
if (oldapp != null) {
|
||||||
db.update(TABLE_APP, values, "id = ?", new String[] { oldapp.id });
|
db.update(TABLE_APP, values, "id = ?", new String[] { oldapp.id });
|
||||||
@ -754,8 +766,8 @@ public class DB {
|
|||||||
values.put("apkName", upapk.apkName);
|
values.put("apkName", upapk.apkName);
|
||||||
values.put("apkSource", upapk.apkSource);
|
values.put("apkSource", upapk.apkSource);
|
||||||
values.put("minSdkVersion", upapk.minSdkVersion);
|
values.put("minSdkVersion", upapk.minSdkVersion);
|
||||||
values.put("permissions", encodeList(upapk.permissions));
|
values.put("permissions", CommaSeparatedList.str(upapk.permissions));
|
||||||
values.put("features", encodeList(upapk.features));
|
values.put("features", CommaSeparatedList.str(upapk.features));
|
||||||
if (oldapk != null) {
|
if (oldapk != null) {
|
||||||
db.update(TABLE_APK, values, "id = ? and version =?", new String[] {
|
db.update(TABLE_APK, values, "id = ? and version =?", new String[] {
|
||||||
oldapk.id, oldapk.version });
|
oldapk.id, oldapk.version });
|
||||||
|
@ -126,9 +126,9 @@ public class RepoXMLHandler extends DefaultHandler {
|
|||||||
curapk.minSdkVersion = 0;
|
curapk.minSdkVersion = 0;
|
||||||
}
|
}
|
||||||
} else if (curel.equals("permissions")) {
|
} else if (curel.equals("permissions")) {
|
||||||
curapk.permissions = DB.decodeList(str);
|
curapk.permissions = DB.CommaSeparatedList.make(str);
|
||||||
} else if (curel.equals("features")) {
|
} else if (curel.equals("features")) {
|
||||||
curapk.features = DB.decodeList(str);
|
curapk.features = DB.CommaSeparatedList.make(str);
|
||||||
}
|
}
|
||||||
} else if (curapp != null && str != null) {
|
} else if (curapp != null && str != null) {
|
||||||
if (curel.equals("id")) {
|
if (curel.equals("id")) {
|
||||||
@ -161,7 +161,7 @@ public class RepoXMLHandler extends DefaultHandler {
|
|||||||
curapp.marketVercode = 0;
|
curapp.marketVercode = 0;
|
||||||
}
|
}
|
||||||
} else if (curel.equals("antifeatures")) {
|
} else if (curel.equals("antifeatures")) {
|
||||||
curapp.antiFeatures = DB.decodeList(str);
|
curapp.antiFeatures = DB.CommaSeparatedList.make(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user