Skip to content

Commit

Permalink
使用entrySet迭代器替代keySet迭代器提高效率 Tencent#48
Browse files Browse the repository at this point in the history
  • Loading branch information
Rkyzzy committed Apr 24, 2021
1 parent ab5c047 commit c38ad8c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions APIJSONORM/src/main/java/apijson/orm/AbstractParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1392,10 +1392,10 @@ public Object getValueByPath(String valuePath) {
}

//取出key被valuePath包含的result,再从里面获取key对应的value
Set<String> set = queryResultMap.keySet();
JSONObject parent = null;
String[] keys = null;
for (String path : set) {
for (Map.Entry<String,Object> entry : queryResultMap.entrySet()){
String path = entry.getKey();
if (valuePath.startsWith(path + "/")) {
try {
parent = (JSONObject) queryResultMap.get(path);
Expand Down
24 changes: 13 additions & 11 deletions APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -1341,16 +1341,17 @@ public Object getWhere(String key, boolean exactMatch) {
return where == null ? null : where.get(key);
}

Set<String> set = key == null || where == null ? null : where.keySet();
if (set != null) {
synchronized (where) {
if (where != null) {
int index;
for (String k : set) {
index = k.indexOf(key);
if (index >= 0 && StringUtil.isName(k.substring(index)) == false) {
return where.get(k);
}
if (key == null || where == null){
return null;
}
synchronized (where) {
if (where != null) {
int index;
for (Map.Entry<String,Object> entry : where.entrySet()) {
String k = entry.getKey();
index = k.indexOf(key);
if (index >= 0 && StringUtil.isName(k.substring(index)) == false) {
return where.get(k);
}
}
}
Expand Down Expand Up @@ -2289,7 +2290,8 @@ public String getSetString(RequestMethod method, Map<String, Object> content, bo
Object value;

String idKey = getIdKey();
for (String key : set) {
for (Map.Entry<String,Object> entry : content.entrySet()) {
String key = entry.getKey();
//避免筛选到全部 value = key == null ? null : content.get(key);
if (key == null || idKey.equals(key)) {
continue;
Expand Down

0 comments on commit c38ad8c

Please sign in to comment.