This is an automated email from the ASF dual-hosted git repository.

kirs pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new a388b68  Optimize HashMap Initial Capacity. (#4896)
a388b68 is described below

commit a388b6853df229bb54c8d46c433f63376809d211
Author: zhuangchong <[email protected]>
AuthorDate: Sat Feb 27 21:36:03 2021 +0800

    Optimize HashMap Initial Capacity. (#4896)
---
 .../apache/dolphinscheduler/api/controller/BaseController.java   | 4 ++--
 .../apache/dolphinscheduler/common/utils/CollectionUtils.java    | 9 ++++++++-
 .../apache/dolphinscheduler/service/quartz/QuartzExecutors.java  | 2 +-
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/BaseController.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/BaseController.java
index c9202d4..f42b554 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/BaseController.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/BaseController.java
@@ -48,7 +48,7 @@ public class BaseController {
      * @return check result code
      */
     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;
         String msg = Status.SUCCESS.getMsg();
         if (pageNo <= 0) {
@@ -202,7 +202,7 @@ public class BaseController {
         result.setCode(Status.SUCCESS.getCode());
         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.CURRENT_PAGE, currentPage);
         map.put(Constants.TOTAL_PAGE, totalPage);
diff --git 
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/CollectionUtils.java
 
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/CollectionUtils.java
index ba55a37..e90c606 100644
--- 
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/CollectionUtils.java
+++ 
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/CollectionUtils.java
@@ -47,6 +47,11 @@ public class CollectionUtils {
     }
 
     /**
+     * The load factor used when none specified in constructor.
+     */
+    static final float DEFAULT_LOAD_FACTOR = 0.75f;
+
+    /**
      * Returns a new {@link Collection} containing <i>a</i> minus a subset of
      * <i>b</i>.  Only the elements of <i>b</i> that satisfy the predicate
      * condition, <i>p</i> are subtracted from <i>a</i>.
@@ -95,6 +100,7 @@ public class CollectionUtils {
      * @return string to map
      */
     public static Map<String, String> stringToMap(String str, String 
separator, String keyPrefix) {
+
         Map<String, String> emptyMap = new HashMap<>(0);
         if (StringUtils.isEmpty(str)) {
             return emptyMap;
@@ -103,7 +109,8 @@ public class CollectionUtils {
             return emptyMap;
         }
         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++) {
             String[] strArray = strings[i].split("=");
             if (strArray.length != 2) {
diff --git 
a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/quartz/QuartzExecutors.java
 
b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/quartz/QuartzExecutors.java
index fd91e40..96209af 100644
--- 
a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/quartz/QuartzExecutors.java
+++ 
b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/quartz/QuartzExecutors.java
@@ -370,7 +370,7 @@ public class QuartzExecutors {
      * @return data map
      */
     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(SCHEDULE_ID, scheduleId);
         dataMap.put(SCHEDULE, JSONUtils.toJsonString(schedule));

Reply via email to