Group Group Group Group Group Group Group Group Group

QueueRingBuffer - double checking for isEmpty in dequeue

#1

Hello,

Method dequeue in QueueRingBuffer can be optimised.
Because read from RingBuffer does a check for isEmpty and returns nil if the buffer is empty.

So, original implementation:

public mutating func dequeue() -> T? {
    return isEmpty ? nil : ringBuffer.read()
}

Can be simplified to:

public mutating func dequeue() -> T? {
    return ringBuffer.read()
}

Thanks for the great book!
Regards, Sergey

#2

@steryokhin Thank you for the heads up - much appreciated!