Browse Source

[1.3.6-prepare][Improvement][Common] Optimize HashMap Initial Capacity #4896 (#4920)

Kirs 4 years ago committed by GitHub
parent
commit
932aadcde5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/BaseController.java
  2. 8
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/CollectionUtils.java
  3. 2
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/quartz/QuartzExecutors.java

4
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/BaseController.java

@ -43,7 +43,7 @@ public class BaseController {
* @return check result code * @return check result code
*/ */
public Map<String, Object> checkPageParams(int pageNo, int pageSize) { public Map<String, Object> checkPageParams(int pageNo, int pageSize) {
Map<String, Object> result = new HashMap<>(2); Map<String, Object> result = new HashMap<>(4);
Status resultEnum = Status.SUCCESS; Status resultEnum = Status.SUCCESS;
String msg = Status.SUCCESS.getMsg(); String msg = Status.SUCCESS.getMsg();
if (pageNo <= 0) { if (pageNo <= 0) {
@ -197,7 +197,7 @@ public class BaseController {
result.setCode(Status.SUCCESS.getCode()); result.setCode(Status.SUCCESS.getCode());
result.setMsg(Status.SUCCESS.getMsg()); result.setMsg(Status.SUCCESS.getMsg());
Map<String, Object> map = new HashMap<>(4); Map<String, Object> map = new HashMap<>(8);
map.put(Constants.TOTAL_LIST, totalList); map.put(Constants.TOTAL_LIST, totalList);
map.put(Constants.CURRENT_PAGE, currentPage); map.put(Constants.CURRENT_PAGE, currentPage);
map.put(Constants.TOTAL_PAGE, totalPage); map.put(Constants.TOTAL_PAGE, totalPage);

8
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/CollectionUtils.java

@ -69,6 +69,11 @@ public class CollectionUtils {
return coll == null || coll.isEmpty(); return coll == null || coll.isEmpty();
} }
/**
* The load factor used when none specified in constructor.
*/
static final float DEFAULT_LOAD_FACTOR = 0.75f;
/** /**
* String to map * String to map
* *
@ -97,7 +102,8 @@ public class CollectionUtils {
return emptyMap; return emptyMap;
} }
String[] strings = str.split(separator); String[] strings = str.split(separator);
Map<String, String> map = new HashMap<>(strings.length); int initialCapacity = (int)(strings.length / DEFAULT_LOAD_FACTOR) + 1;
Map<String, String> map = new HashMap<>(initialCapacity);
for (int i = 0; i < strings.length; i++) { for (int i = 0; i < strings.length; i++) {
String[] strArray = strings[i].split("="); String[] strArray = strings[i].split("=");
if (strArray.length != 2) { if (strArray.length != 2) {

2
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/quartz/QuartzExecutors.java

@ -331,7 +331,7 @@ public class QuartzExecutors {
* @return data map * @return data map
*/ */
public static Map<String, Object> buildDataMap(int projectId, int scheduleId, Schedule schedule) { public static Map<String, Object> buildDataMap(int projectId, int scheduleId, Schedule schedule) {
Map<String, Object> dataMap = new HashMap<>(3); Map<String, Object> dataMap = new HashMap<>(8);
dataMap.put(PROJECT_ID, projectId); dataMap.put(PROJECT_ID, projectId);
dataMap.put(SCHEDULE_ID, scheduleId); dataMap.put(SCHEDULE_ID, scheduleId);
dataMap.put(SCHEDULE, JSONUtils.toJson(schedule)); dataMap.put(SCHEDULE, JSONUtils.toJson(schedule));

Loading…
Cancel
Save