You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2021/02/07 06:46:12 UTC

[shardingsphere] branch master updated: Optimize ManualBitSet (#9367)

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

menghaoran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 770d36a  Optimize ManualBitSet (#9367)
770d36a is described below

commit 770d36af742a7fa09d535daf20aa429088b12e5b
Author: 邱鹿 Lucas <lu...@163.com>
AuthorDate: Sun Feb 7 14:45:41 2021 +0800

    Optimize ManualBitSet (#9367)
    
    Co-authored-by: qiulu3 <Lucas209910>
---
 .../scaling/core/common/channel/distribution/ManualBitSet.java      | 2 +-
 .../scaling/core/common/channel/distribution/ManualBitSetTest.java  | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/common/channel/distribution/ManualBitSet.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/common/channel/distribution/ManualBitSet.java
index 26e7344..debe8b4 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/common/channel/distribution/ManualBitSet.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/common/channel/distribution/ManualBitSet.java
@@ -90,7 +90,7 @@ public final class ManualBitSet {
         if (size == 0) {
             return fromIndex;
         }
-        int correctIndex = (int) (fromIndex - startIndex);
+        int correctIndex = fromIndex < startIndex ? 0 : (int) (fromIndex - startIndex);
         int listIndex = correctIndex / BIT_SET_SIZE;
         int count = size;
         for (int i = listIndex; i < bitSets.size(); i++) {
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/common/channel/distribution/ManualBitSetTest.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/common/channel/distribution/ManualBitSetTest.java
index 48f069a..67b24b8 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/common/channel/distribution/ManualBitSetTest.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/common/channel/distribution/ManualBitSetTest.java
@@ -46,8 +46,10 @@ public final class ManualBitSetTest {
     @Test
     public void assertGetEndIndexSuccess() {
         ManualBitSet bitSet = new ManualBitSet();
-        IntStream.range(0, 10).filter(each -> each % 2 == 1).forEach(bitSet::set);
-        assertThat(bitSet.getEndIndex(0L, 5), is(10L));
+        IntStream.range(1024, 1100).filter(each -> each % 2 == 1).forEach(bitSet::set);
+        assertThat(bitSet.getEndIndex(0L, 5), is(1034L));
+        bitSet.clear(1025);
+        assertThat(bitSet.getEndIndex(0L, 5), is(1034L));
     }
     
     @Test(expected = IndexOutOfBoundsException.class)