Motivation:
`MarkedCircularBuffer.popFirst()` asserts that the backing buffer should
contain more than zero elements yet `popFirst()` allows `nil` to be
returned when there is no value to return.
Modifications:
- Move the assertion from `popFirst() -> Element?` to `removeFirst() -> Element`
- Test for `popFirst()`
Result:
- We can safely call `popFirst()` on an empty `MarkedCircularBuffer` in
debug mode.
Motivation:
The Swift compiler actively tries to make our live hard and puts all
initialisations of variables that are initialised using the shorthand
syntax
@usableFromInline var myVar: MyVarType = .init()
into a _non-inlinable_ function
variable initialization expression of MyModule.MyType.myVar : MyVarType
This means that the following pattern
public struct MyType {
@usableFromInline var myVar: MyVarType = .init()
@inlinable public init() {
}
}
leads to code for the `init` that looks like
CALL variable_initialization_expression_...
instead of also inlining the the code for the variable initialiser.
Modifications:
Don't use `@usableFromInline var myVar: MyVarType = ...` anywhere,
instead put it explicitly into the @inlinable `init`s which makes
actually inlinable.
I even removed that syntax from places where it doesn't matter
(eg. non-@inlinable inits) for consistency and in case someone were to
make the init inlinable later.
Result:
Minor performance wins working around https://bugs.swift.org/browse/SR-11768
Motivation:
While CircularBuffer has an inlinable implementation to improve performance, MarkedCircularBuffer
never got enhanced to have it. This harms performance in many core NIO libraries which heavily use
MCB, forcing heap allocations on almost all MCB operations.
Modifications:
- Make basically everything on MarkedCircularBuffer inlinable.
Result:
Faster code.
Motivation:
CircularBuffer and its indices should be small. Also the implementation
of methods like remove/popFirst/Last was suboptimal.
Modifications:
- shrink CircularBuffer and its indices
- improve the conformances to the various collection related protocols
- make CircularBuffer self-slicing
- remove Strideable conformance from the indices
Result:
nicer CircularBuffer
Motivation:
MarkedCircularBuffer was assuming that indices remain stable across
mutations, that's wrong.
Modifications:
Don't store the marked index but rather the offset from the start
instead.
Result:
MarkedCircularBuffer uses indices correctly.
Motivation:
Opaque indices are a good idea for collections, (Marked)CircularBuffer
should use those too.
Modifications:
Cheapest possible implementation for opaque indices, could be much
improved. This is the cheapest possible implementation for opaque
indices and this could be much improved later, see #682 but the
improvements won't be SemVer major :).
Result:
first stab at #682
Motivation:
initialRingCapacity is not a great name, initialCapacity is much better
Modifications:
rename CircularBuffer(initialRingCapacity:) to initialCapacity
Result:
more consistent code
Motivation:
We now depend on Swift 5.0, so we can remove all the backporting of
functionality.
Modifications:
deleted all backported Swift functionality
Result:
less code
* Change unnecessary functions to variables
Motivation:
The changed functions do not have any side effects and therefore better convey intent when being a simple computed variable.
Modifications:
Changes:
- `func markedElementIndex() -> Int?` to `var markedElementIndex: Int?`
- `func markedElement() -> E?` to `var markedElement: E?`
- `func hasMark() -> Bool` to `var hasMark: Bool`
Result:
- improved code quality
Motivation:
We should explain why this typealias
public typealias RangeType<Bound> = CountableRange<Bound> where Bound: Strideable, Bound.Stride: SignedInteger
isn't just
public typealias RangeType = CountableRange
and that's because SR-6963.
Modifications:
added a comment explaining why
Result:
code easier to read
Motivation:
SR-6963 is currently blocking builds with Swift 4.2 pre-releases, we
should work around it.
Modifications:
work around SR-6963.
Result:
builds with 4.2 pre-release
Motivation:
Warnings are bad.
Modifications:
Changed things that still work in 4.0/4.1 but are warnings in 4.2 to
improved versions.
Result:
less warnings on the upcoming 4.2
fix some typos, force unwraps and inconsistencies
Motivation:
Reviewing the code I found a few typos that hindered readability, some unnecessary force unwraps and inconsistencies in the codebase.
Modifications:
- The main file in NIOWebSocketServer now accepts command line arguments
and binds to a passed in host and port like the other server examples do.
- Minor typo fixes
- removed one force unwrap
Result:
- The result of my change will bring the NIOWebSocketServer more inline
with how the NIOHTTP1 and NIOChat servers examples are setup.
- less force unwrapping
- fewer typos
[message edited by @weissi]
Motivation:
We used precondition for a few cases where it really checks for our own implementation. We should use assert here as there is nothing the user really can do to trigger it.
Modifications:
Replace precondition with assert.
Result:
Less overhead when in release mode and more correct in general.