forked from crystal-lang/crystal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle case folding in
String#compare
correctly (crystal-lang#13532)
- Loading branch information
1 parent
8febc9b
commit 9ef62d9
Showing
6 changed files
with
217 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module Crystal | ||
# :nodoc: | ||
# An internal deque type whose storage is backed by a `StaticArray`. The deque | ||
# capacity is fixed to N and storing more than N elements is an error. Only a | ||
# subset of `::Deque`'s functionality is defined as needed. | ||
struct SmallDeque(T, N) | ||
include Indexable::Mutable(T) | ||
|
||
@start = 0 | ||
@buffer = uninitialized T[N] | ||
getter size : Int32 = 0 | ||
|
||
def unsafe_fetch(index : Int) : T | ||
index_to_ptr(index).value | ||
end | ||
|
||
def unsafe_put(index : Int, value : T) | ||
index_to_ptr(index).value = value | ||
end | ||
|
||
def <<(value : T) | ||
check_capacity_for_insert | ||
unsafe_put(@size, value) | ||
@size += 1 | ||
self | ||
end | ||
|
||
def shift(&) | ||
if @size == 0 | ||
yield | ||
else | ||
ptr = index_to_ptr(0) | ||
value = ptr.value | ||
ptr.clear | ||
@size &-= 1 | ||
@start &+= 1 | ||
@start &-= N if @start >= N | ||
value | ||
end | ||
end | ||
|
||
# precondition: 0 <= index <= N | ||
private def index_to_ptr(index) | ||
index &+= @start | ||
index &-= N if index >= N | ||
@buffer.to_unsafe + index | ||
end | ||
|
||
private def check_capacity_for_insert | ||
raise "Out of capacity" if @size >= N | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.