public void removeFromFirst(final int toIndex) {
        int alignedIndex = toIndex + this.firstOffset;
        int toSegmentIndex = alignedIndex >> SEGMENT_SHIFT;

        int toIndexInSeg = alignedIndex & (SEGMENT_SIZE - 1);

        if (toSegmentIndex > 0) {
            for (int i = 0; i < toSegmentIndex; i++) {
                this.estimatedBytes -= this.segments.get(i).bytes();
            }
            this.segments.removeRange(0, toSegmentIndex);
            this.size -= ((toSegmentIndex << SEGMENT_SHIFT) - this.firstOffset);
        }

        Segment<T> firstSeg = this.getFirst();
        if (firstSeg != null) {
            long[] results = firstSeg.removeFromFirst(toIndexInSeg);
            this.size -= (int) results[0];
            this.estimatedBytes -= results[1];
            this.firstOffset = firstSeg.offset;
            if (firstSeg.isEmpty()) {
                RecycleUtil.recycle(this.segments.pollFirst());
                this.firstOffset = 0;
            }
        } else {
            this.estimatedBytes = this.firstOffset = this.size = 0;
        }
    }
Removes from this list all of the elements whose index is between
0, inclusive, and {@code toIndex}, exclusive.
Shifts any succeeding elements to the left (reduces their index).
jraft-core/src/main/java/com/alipay/sofa/jraft/util/SegmentList.java