Skip to content

Commit e2b3edb

Browse files
author
Yury Shubin
committed
optimization #3
1 parent 9ff49c5 commit e2b3edb

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/com/activeandroid/Model.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public abstract class Model {
4949
private final TableInfo mTableInfo;
5050
private final String idName;
5151
private static Map<String, List<Integer>> columnIndexesCache = new HashMap<String, List<Integer>>();
52+
private static Map<String, List<Class>> fieldTypesCache = new HashMap<String, List<Class>>();
5253

5354
//////////////////////////////////////////////////////////////////////////////////////
5455
// CONSTRUCTORS
@@ -194,17 +195,25 @@ public final void loadFromCursor(Cursor cursor) {
194195
columnIndexes = new ArrayList<Integer>();
195196
columnIndexesCache.put(mTableInfo.getTableName(), columnIndexes);
196197
}
198+
List<Class> fieldTypes = fieldTypesCache.get(mTableInfo.getTableName());
199+
if (fieldTypes == null) {
200+
fieldTypes = new ArrayList<Class>();
201+
fieldTypesCache.put(mTableInfo.getTableName(), fieldTypes);
202+
}
197203
int counter = 0;
198204
for (Field field : mTableInfo.getFields()) {
199-
Class<?> fieldType = field.getType();
200-
201205
final int columnIndex;
206+
Class<?> fieldType;
202207
if (columnIndexes.size() <= counter) {
203208
String fieldName = mTableInfo.getColumnName(field);
204209
columnIndex = columnsOrdered.indexOf(fieldName);
205210
columnIndexes.add(columnIndex);
211+
212+
fieldType = field.getType();
213+
fieldTypes.add(fieldType);
206214
} else {
207215
columnIndex = columnIndexes.get(counter);
216+
fieldType = fieldTypes.get(counter);
208217
}
209218

210219
if (columnIndex < 0) {

0 commit comments

Comments
 (0)