Skip to content

Commit

Permalink
optimization #3
Browse files Browse the repository at this point in the history
  • Loading branch information
yshubin committed Aug 16, 2015
1 parent bbd7429 commit 80f7397
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/com/activeandroid/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public abstract class Model {
private final TableInfo mTableInfo;
private final String idName;
private static Map<String, List<Integer>> columnIndexesCache = new HashMap<String, List<Integer>>();
private static Map<String, List<Class>> fieldTypesCache = new HashMap<String, List<Class>>();

//////////////////////////////////////////////////////////////////////////////////////
// CONSTRUCTORS
Expand Down Expand Up @@ -194,17 +195,25 @@ public final void loadFromCursor(Cursor cursor) {
columnIndexes = new ArrayList<Integer>();
columnIndexesCache.put(mTableInfo.getTableName(), columnIndexes);
}
List<Class> fieldTypes = fieldTypesCache.get(mTableInfo.getTableName());
if (fieldTypes == null) {
fieldTypes = new ArrayList<Class>();
fieldTypesCache.put(mTableInfo.getTableName(), fieldTypes);
}
int counter = 0;
for (Field field : mTableInfo.getFields()) {
Class<?> fieldType = field.getType();

final int columnIndex;
Class<?> fieldType;
if (columnIndexes.size() <= counter) {
String fieldName = mTableInfo.getColumnName(field);
columnIndex = columnsOrdered.indexOf(fieldName);
columnIndexes.add(columnIndex);

fieldType = field.getType();
fieldTypes.add(fieldType);
} else {
columnIndex = columnIndexes.get(counter);
fieldType = fieldTypes.get(counter);
}

if (columnIndex < 0) {
Expand Down

0 comments on commit 80f7397

Please sign in to comment.