-
Notifications
You must be signed in to change notification settings - Fork 260
Fix CircularBuffer inner constructor #949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix CircularBuffer inner constructor #949
Conversation
function CircularBuffer{T}(iter, capacity::Integer) where {T} | ||
vec = copyto!(Vector{T}(undef,capacity), iter) | ||
CircularBuffer{T}(1, length(iter),vec) | ||
vec = copyto!(Vector{T}(undef, capacity), iter) | ||
CircularBuffer{T}(1, length(iter), vec) | ||
end | ||
|
||
CircularBuffer(capacity::Integer) = CircularBuffer{Any}(capacity) | ||
|
||
CircularBuffer{T}(capacity::Integer) where {T} = CircularBuffer{T}(T[],capacity) | ||
CircularBuffer{T}(capacity::Integer) where {T} = CircularBuffer{T}(T[], capacity) | ||
|
||
CircularBuffer(iter,capacity::Integer) = CircularBuffer{eltype(iter)}(iter,capacity) | ||
CircularBuffer(iter, capacity::Integer) = CircularBuffer{eltype(iter)}(iter, capacity) | ||
|
||
function CircularBuffer{T}(iter) where {T} | ||
vec = reshape(collect(T,iter),:) | ||
vec = reshape(collect(T, iter), :) | ||
CircularBuffer{T}(1, length(vec), vec) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are just formatting fixes
f <= length(buf) || throw(ArgumentError("Value of 'first' must be inbounds of buffer")) | ||
len <= length(buf) || throw(ArgumentError("Value of 'length' must be <= length of buffer")) | ||
return new{T}(length(buf), f, len, buf) | ||
end | ||
|
||
# Convert any `Integer` to whatever `Int` is on the relevant machine | ||
CircularBuffer{T}(f::Integer, len::Integer, buf::Integer) where {T} = CircularBuffer{T}(Int(f), Int(len), Int(buf)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This constructor could be removed entirely, as it was just never called in the previous version. However it seems that #893 decided to keep it
1feac5b
to
b6058cf
Compare
What is this fixing? |
Nothing was actually broken before. The issue is that there is an inner constructor: This constructor was already superfluous because of #893 (comment) , so there's no change in behaviour, but this PR just implements the original intention in that linked PR. |
No description provided.