zrlw commented on code in PR #16395:
URL: https://github.com/apache/dubbo/pull/16395#discussion_r3655662742
##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/BitList.java:
##########
@@ -114,16 +114,26 @@ public synchronized E getByIndex(int index) {
}
/**
- * And operation between two bitList. Return a new cloned list.
- * TailList in source bitList will be totally saved even if it is not
appeared in the target bitList.
+ * And operation between two bitList.
*
* @param target target bitList
- * @return this bitList only contains those elements contain in both two
list and source bitList's tailList
+ * @return this bitList only contains elements contained in both lists
*/
public synchronized BitList<E> and(BitList<E> target) {
- rootSet.and(target.rootSet);
- if (target.getTailList() != null) {
- target.getTailList().forEach(this::addToTailList);
+ if (originList == target.originList) {
+ rootSet.and(target.rootSet);
+ } else {
+ BitSet resultSet = new BitSet();
+ for (int bitIndex = rootSet.nextSetBit(0); bitIndex >= 0; bitIndex
= rootSet.nextSetBit(bitIndex + 1)) {
+ if (target.contains(originList.get(bitIndex))) {
+ resultSet.set(bitIndex);
+ }
+ }
+ rootSet.clear();
+ rootSet.or(resultSet);
+ }
+ if (CollectionUtils.isNotEmpty(tailList)) {
+ tailList.removeIf(e -> !target.contains(e));
Review Comment:
Conflict with the method comment?
```
TailList in source bitList will be totally saved even if it is not appeared
in the target bitList.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]