You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by cr...@apache.org on 2022/04/20 08:37:21 UTC

[dubbo] branch 3.0 updated: Init map size (#9943)

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

crazyhzm pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.0 by this push:
     new 6364371e71 Init map size (#9943)
6364371e71 is described below

commit 6364371e71c82831397b54d5852a6cdb4d5021fc
Author: Oliver <wq...@163.com>
AuthorDate: Wed Apr 20 16:37:15 2022 +0800

    Init map size (#9943)
---
 .../dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AppResponse.java | 4 ++--
 .../src/main/java/org/apache/dubbo/rpc/protocol/AbstractInvoker.java  | 2 +-
 .../org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java  | 2 +-
 .../dubbo/rpc/protocol/grpc/interceptors/RpcContextInterceptor.java   | 2 +-
 .../java/org/apache/dubbo/rpc/protocol/tri/call/TripleClientCall.java | 2 +-
 .../dubbo/rpc/protocol/tri/transport/AbstractH2TransportListener.java | 4 ++--
 6 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AppResponse.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AppResponse.java
index 4f148ee02b..3bcc4ae7b7 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AppResponse.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AppResponse.java
@@ -145,7 +145,7 @@ public class AppResponse implements Result {
             return;
         }
         if (this.attachments == null) {
-            this.attachments = new HashMap<>();
+            this.attachments = new HashMap<>(map.size());
         }
         this.attachments.putAll(map);
     }
@@ -156,7 +156,7 @@ public class AppResponse implements Result {
             return;
         }
         if (this.attachments == null) {
-            this.attachments = new HashMap<>();
+            this.attachments = new HashMap<>(map.size());
         }
         this.attachments.putAll(map);
     }
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractInvoker.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractInvoker.java
index 3ce1c207be..b8c389f289 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractInvoker.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractInvoker.java
@@ -119,7 +119,7 @@ public abstract class AbstractInvoker<T> implements Invoker<T> {
         if (ArrayUtils.isEmpty(keys)) {
             return null;
         }
-        Map<String, Object> attachment = new HashMap<>();
+        Map<String, Object> attachment = new HashMap<>(keys.length);
         for (String key : keys) {
             String value = url.getParameter(key);
             if (value != null && value.length() > 0) {
diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java
index a67c935cfa..b63f86cdb8 100644
--- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java
+++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java
@@ -219,7 +219,7 @@ public class DecodeableRpcInvocation extends RpcInvocation implements Codec, Dec
             if (CollectionUtils.isNotEmptyMap(map)) {
                 Map<String, Object> attachment = getObjectAttachments();
                 if (attachment == null) {
-                    attachment = new HashMap<>();
+                    attachment = new HashMap<>(map.size());
                 }
                 attachment.putAll(map);
                 setObjectAttachments(attachment);
diff --git a/dubbo-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/interceptors/RpcContextInterceptor.java b/dubbo-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/interceptors/RpcContextInterceptor.java
index 703223125c..2230438f92 100644
--- a/dubbo-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/interceptors/RpcContextInterceptor.java
+++ b/dubbo-rpc/dubbo-rpc-grpc/src/main/java/org/apache/dubbo/rpc/protocol/grpc/interceptors/RpcContextInterceptor.java
@@ -69,7 +69,7 @@ public class RpcContextInterceptor implements ClientInterceptor, ServerIntercept
     @Override
     public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
         Set<String> keys = headers.keys();
-        Map<String, Object> attachments = new HashMap<>();
+        Map<String, Object> attachments = new HashMap<>(keys.size());
         // filter out all dubbo attachments and save in map
         if (keys != null) {
             keys.stream().filter(k -> k.toUpperCase().startsWith(DUBBO)).forEach(k ->
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/TripleClientCall.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/TripleClientCall.java
index 77665a327e..b13af798cd 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/TripleClientCall.java
+++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/TripleClientCall.java
@@ -161,7 +161,7 @@ public class TripleClientCall implements ClientCall, ClientStream.Listener {
     }
 
     private Map<Class<?>, Object> tranFromStatusDetails(List<Any> detailList) {
-        Map<Class<?>, Object> map = new HashMap<>();
+        Map<Class<?>, Object> map = new HashMap<>(detailList.size());
         try {
             for (Any any : detailList) {
                 if (any.is(ErrorInfo.class)) {
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/transport/AbstractH2TransportListener.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/transport/AbstractH2TransportListener.java
index 0c0d104151..d3bcc86a1b 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/transport/AbstractH2TransportListener.java
+++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/transport/AbstractH2TransportListener.java
@@ -43,7 +43,7 @@ public abstract class AbstractH2TransportListener implements H2TransportListener
         if (trailers == null) {
             return Collections.emptyMap();
         }
-        Map<String, Object> attachments = new HashMap<>();
+        Map<String, Object> attachments = new HashMap<>(trailers.size());
         for (Map.Entry<CharSequence, CharSequence> header : trailers) {
             String key = header.getKey().toString();
             if (key.endsWith(TripleConstant.HEADER_BIN_SUFFIX)
@@ -68,7 +68,7 @@ public abstract class AbstractH2TransportListener implements H2TransportListener
         if (trailers == null) {
             return Collections.emptyMap();
         }
-        Map<String, String> excludeHeaders = new HashMap<>();
+        Map<String, String> excludeHeaders = new HashMap<>(trailers.size());
         for (Map.Entry<CharSequence, CharSequence> header : trailers) {
             String key = header.getKey().toString();
             if (Http2Headers.PseudoHeaderName.isPseudoHeader(key)) {