     public mutating func mark() {
         let count = self.buffer.count
         if count > 0 {
-            self.markedIndex = self.endIndex.advanced(by: -1)
+            self.markedIndexOffset = count - 1
         } else {
-            assert(self.markedIndex == nil, "marked index is \(self.markedIndex.debugDescription)")
+            assert(self.markedIndexOffset == nil, "marked index is \(self.markedIndexOffset.debugDescription)")
         }
     }
 

    /// Removes the first element from the buffer.
    public mutating func removeFirst() -> Element {
        assert(self.buffer.count > 0)
        if let markedIndex = self.markedIndex {
            if markedIndex == self.startIndex {
                self.markedIndex = nil
            } else {
                self.markedIndex = markedIndex.advanced(by: -1)
            }
        }
        return self.buffer.removeFirst()

    public typealias Index = CircularBuffer<Element>.Index

    private var buffer: CircularBuffer<Element>
    private var markedIndexOffset: Int? = nil /* nil: nothing marked */

    /// Create a new instance.
    ///
