Skip to content
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

Refactor Indexable::Mutable#fill's overloads #11368

Merged

Conversation

HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented Oct 26, 2021

This PR reworks Indexable::Mutable#fill's overloads so that they follow the convention of other subrange-accepting methods in the Crystal standard library.

  • The following overloads are now available in Indexable::Mutable(T):
    • #fill(value : T, start : Int, count : Int)
    • #fill(value : T, range : Range)
    • #fill(start : Int, count : Int, & : Int32 -> T)
    • #fill(range : Range, & : Int32 -> T)
  • Array(T)#fill(value : T, start : Int) and Array(T)#fill(start : Int, & : Int32 -> T) are now deprecated. They are redundant because the Range overloads take care of them with a start.. argument; no other method in the standard library has such an overload on top of start + count and range ones.
  • Having start == size or start + count > size no longer raise an exception. #fill will now replace fewer than count elements in that case (possibly zero). This is also the behaviour in Ruby.
  • The non-block overloads in Array and StaticArray delegate to their underlying Slices to take advantage of the memset optimization. This includes also the subrange-accepting overloads.

@oprypin oprypin self-requested a review October 30, 2021 14:11
@straight-shoota straight-shoota added this to the 1.3.0 milestone Nov 7, 2021
src/array.cr Show resolved Hide resolved
@straight-shoota straight-shoota merged commit 207bdc6 into crystal-lang:master Nov 10, 2021
@HertzDevil HertzDevil deleted the refactor/indexable-mutable-fill branch November 14, 2021 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants