Skip to content

Commit c38ad8c

Browse files
committed
使用entrySet迭代器替代keySet迭代器提高效率 Tencent#48
1 parent ab5c047 commit c38ad8c

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

APIJSONORM/src/main/java/apijson/orm/AbstractParser.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1392,10 +1392,10 @@ public Object getValueByPath(String valuePath) {
13921392
}
13931393

13941394
//取出key被valuePath包含的result,再从里面获取key对应的value
1395-
Set<String> set = queryResultMap.keySet();
13961395
JSONObject parent = null;
13971396
String[] keys = null;
1398-
for (String path : set) {
1397+
for (Map.Entry<String,Object> entry : queryResultMap.entrySet()){
1398+
String path = entry.getKey();
13991399
if (valuePath.startsWith(path + "/")) {
14001400
try {
14011401
parent = (JSONObject) queryResultMap.get(path);

APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java

+13-11
Original file line numberDiff line numberDiff line change
@@ -1341,16 +1341,17 @@ public Object getWhere(String key, boolean exactMatch) {
13411341
return where == null ? null : where.get(key);
13421342
}
13431343

1344-
Set<String> set = key == null || where == null ? null : where.keySet();
1345-
if (set != null) {
1346-
synchronized (where) {
1347-
if (where != null) {
1348-
int index;
1349-
for (String k : set) {
1350-
index = k.indexOf(key);
1351-
if (index >= 0 && StringUtil.isName(k.substring(index)) == false) {
1352-
return where.get(k);
1353-
}
1344+
if (key == null || where == null){
1345+
return null;
1346+
}
1347+
synchronized (where) {
1348+
if (where != null) {
1349+
int index;
1350+
for (Map.Entry<String,Object> entry : where.entrySet()) {
1351+
String k = entry.getKey();
1352+
index = k.indexOf(key);
1353+
if (index >= 0 && StringUtil.isName(k.substring(index)) == false) {
1354+
return where.get(k);
13541355
}
13551356
}
13561357
}
@@ -2289,7 +2290,8 @@ public String getSetString(RequestMethod method, Map<String, Object> content, bo
22892290
Object value;
22902291

22912292
String idKey = getIdKey();
2292-
for (String key : set) {
2293+
for (Map.Entry<String,Object> entry : content.entrySet()) {
2294+
String key = entry.getKey();
22932295
//避免筛选到全部 value = key == null ? null : content.get(key);
22942296
if (key == null || idKey.equals(key)) {
22952297
continue;

0 commit comments

Comments
 (0)