-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimize: Local variable 'map' is redundant and check queue offer return value #3188
Conversation
core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java
Show resolved
Hide resolved
if (basket == null) { | ||
map.putIfAbsent(serverAddress, new LinkedBlockingQueue<>()); | ||
basket = map.get(serverAddress); | ||
basketMap.putIfAbsent(serverAddress, new LinkedBlockingQueue<>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basketMap.computeIfAbsent(serverAddress, k -> new LinkedBlockingQueue<>());
I think it's better that way. what do you think?
* origin/develop: optimize: Local variable 'map' is redundant and check queue offer return value apache#3187
Codecov Report
@@ Coverage Diff @@
## develop #3188 +/- ##
=============================================
- Coverage 51.03% 51.03% -0.01%
+ Complexity 3281 3246 -35
=============================================
Files 612 608 -4
Lines 20112 19975 -137
Branches 2517 2495 -22
=============================================
- Hits 10265 10195 -70
+ Misses 8820 8764 -56
+ Partials 1027 1016 -11 |
map.putIfAbsent(serverAddress, new LinkedBlockingQueue<>()); | ||
basket = map.get(serverAddress); | ||
basketMap.computeIfAbsent(serverAddress, k -> new LinkedBlockingQueue<>()); | ||
if (!basketMap.get(serverAddress).offer(rpcMessage)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not need to get again
BlockingQueue<RpcMessage> basket = basketMap.computeIfAbsent(serverAddress, k -> new LinkedBlockingQueue<>());
if (!basket .offer(rpcMessage)) {
......
}
core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java
Outdated
Show resolved
Hide resolved
* origin/develop: optimize: Local variable 'map' is redundant and check queue offer return value apache#3187
* origin/develop:
core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java
Outdated
Show resolved
Hide resolved
* origin/develop:
* origin/develop:
* origin/develop:
* origin/develop:
请绑定一下githubid到你本地的git插件上 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
解决一下冲突,再绑定一下githubid到你本地的git插件上push一下 |
Ⅰ. Describe what this PR did
https://github.com/seata/seata/blob/6c0c75939dedbf19c4a21a8ac7aa0fb98879a8fd/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java#L156
// put message into basketMap
ConcurrentHashMap<String, BlockingQueue> map = basketMap;
BlockingQueue basket = map.get(serverAddress);
if (basket == null) {
map.putIfAbsent(serverAddress, new LinkedBlockingQueue<>());
basket = map.get(serverAddress);
}
basket.offer(rpcMessage);
1.remove redundant local variable 'map';
2.check the BlockingQueue offer return value;
Ⅱ. Does this pull request fix one issue?
fixes #3187
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews