cassandra-pr mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aweisberg <...@git.apache.org>
Subject [GitHub] cassandra pull request #271: 14726
Date Wed, 26 Sep 2018 15:50:57 GMT
Github user aweisberg commented on a diff in the pull request:

    https://github.com/apache/cassandra/pull/271#discussion_r220621697
  
    --- Diff: src/java/org/apache/cassandra/locator/AbstractReplicaCollection.java ---
    @@ -58,45 +63,332 @@
             };
         }
     
    -    protected final List<Replica> list;
    -    protected final boolean isSnapshot;
    -    protected AbstractReplicaCollection(List<Replica> list, boolean isSnapshot)
    +    /**
    +     * A simple list with no comodification checks and immutability by default (only
append permitted, and only one initial copy)
    +     * this permits us to reduce the amount of garbage generated, by not wrapping iterators
or unnecessarily copying
    +     * and reduces the amount of indirection necessary, as well as ensuring monomorphic
callsites
    +     */
    +    protected static class ReplicaList implements Iterable<Replica>
         {
    -        this.list = list;
    -        this.isSnapshot = isSnapshot;
    +        private static final Replica[] EMPTY = new Replica[0];
    +        Replica[] contents;
    +        int begin, size;
    +
    +        public ReplicaList() { this(0); }
    +        public ReplicaList(int capacity) { contents = capacity == 0 ? EMPTY : new Replica[capacity];
}
    +        public ReplicaList(Replica[] contents, int begin, int size) { this.contents =
contents; this.begin = begin; this.size = size; }
    +
    +        public boolean isSubList(ReplicaList subList)
    +        {
    +            return subList.contents == contents;
    +        }
    +
    +        public Replica get(int index)
    +        {
    +            if (index > size)
    +                throw new IndexOutOfBoundsException();
    +            return contents[begin + index];
    +        }
    +
    +        public void add(Replica replica)
    +        {
    +            // can only add to full array - if we have sliced it, we must be a snapshot
    +            assert begin == 0;
    --- End diff --
    
    Shouldn't be possible to disable this check.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Mime
View raw message