mirror of
https://github.com/roc-lang/roc.git
synced 2025-11-25 13:36:37 +00:00
Add listGetUnsafe to Dict.roc rather than exposing from list
This commit is contained in:
parent
5a86f611fa
commit
12ecdab4c5
4 changed files with 24 additions and 16 deletions
|
|
@ -233,6 +233,10 @@ LowLevelHasher := { originalSeed : U64, state : U64 } has [
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# unsafe primitive that does not perform a bounds check
|
||||||
|
# TODO hide behind an InternalList.roc module
|
||||||
|
listGetUnsafe : List a, Nat -> a
|
||||||
|
|
||||||
createLowLevelHasher : { seed ?U64 } -> LowLevelHasher
|
createLowLevelHasher : { seed ?U64 } -> LowLevelHasher
|
||||||
createLowLevelHasher = \{ seed ? 0x526F_6352_616E_643F } ->
|
createLowLevelHasher = \{ seed ? 0x526F_6352_616E_643F } ->
|
||||||
@LowLevelHasher { originalSeed: seed, state: seed }
|
@LowLevelHasher { originalSeed: seed, state: seed }
|
||||||
|
|
@ -400,14 +404,14 @@ wyr8 = \list, index ->
|
||||||
# With seamless slices and Num.fromBytes, this should be possible to make faster and nicer.
|
# With seamless slices and Num.fromBytes, this should be possible to make faster and nicer.
|
||||||
# It would also deal with the fact that on big endian systems we want to invert the order here.
|
# It would also deal with the fact that on big endian systems we want to invert the order here.
|
||||||
# Without seamless slices, we would need fromBytes to take an index.
|
# Without seamless slices, we would need fromBytes to take an index.
|
||||||
p1 = List.getUnsafe list index |> Num.toU64
|
p1 = listGetUnsafe list index |> Num.toU64
|
||||||
p2 = List.getUnsafe list (Num.addWrap index 1) |> Num.toU64
|
p2 = listGetUnsafe list (Num.addWrap index 1) |> Num.toU64
|
||||||
p3 = List.getUnsafe list (Num.addWrap index 2) |> Num.toU64
|
p3 = listGetUnsafe list (Num.addWrap index 2) |> Num.toU64
|
||||||
p4 = List.getUnsafe list (Num.addWrap index 3) |> Num.toU64
|
p4 = listGetUnsafe list (Num.addWrap index 3) |> Num.toU64
|
||||||
p5 = List.getUnsafe list (Num.addWrap index 4) |> Num.toU64
|
p5 = listGetUnsafe list (Num.addWrap index 4) |> Num.toU64
|
||||||
p6 = List.getUnsafe list (Num.addWrap index 5) |> Num.toU64
|
p6 = listGetUnsafe list (Num.addWrap index 5) |> Num.toU64
|
||||||
p7 = List.getUnsafe list (Num.addWrap index 6) |> Num.toU64
|
p7 = listGetUnsafe list (Num.addWrap index 6) |> Num.toU64
|
||||||
p8 = List.getUnsafe list (Num.addWrap index 7) |> Num.toU64
|
p8 = listGetUnsafe list (Num.addWrap index 7) |> Num.toU64
|
||||||
a = Num.bitwiseOr p1 (Num.shiftLeftBy p2 8)
|
a = Num.bitwiseOr p1 (Num.shiftLeftBy p2 8)
|
||||||
b = Num.bitwiseOr (Num.shiftLeftBy p3 16) (Num.shiftLeftBy p4 24)
|
b = Num.bitwiseOr (Num.shiftLeftBy p3 16) (Num.shiftLeftBy p4 24)
|
||||||
c = Num.bitwiseOr (Num.shiftLeftBy p5 32) (Num.shiftLeftBy p6 40)
|
c = Num.bitwiseOr (Num.shiftLeftBy p5 32) (Num.shiftLeftBy p6 40)
|
||||||
|
|
@ -418,10 +422,10 @@ wyr8 = \list, index ->
|
||||||
# Get the next 4 bytes as a U64 with some shifting.
|
# Get the next 4 bytes as a U64 with some shifting.
|
||||||
wyr4 : List U8, Nat -> U64
|
wyr4 : List U8, Nat -> U64
|
||||||
wyr4 = \list, index ->
|
wyr4 = \list, index ->
|
||||||
p1 = List.getUnsafe list index |> Num.toU64
|
p1 = listGetUnsafe list index |> Num.toU64
|
||||||
p2 = List.getUnsafe list (Num.addWrap index 1) |> Num.toU64
|
p2 = listGetUnsafe list (Num.addWrap index 1) |> Num.toU64
|
||||||
p3 = List.getUnsafe list (Num.addWrap index 2) |> Num.toU64
|
p3 = listGetUnsafe list (Num.addWrap index 2) |> Num.toU64
|
||||||
p4 = List.getUnsafe list (Num.addWrap index 3) |> Num.toU64
|
p4 = listGetUnsafe list (Num.addWrap index 3) |> Num.toU64
|
||||||
a = Num.bitwiseOr p1 (Num.shiftLeftBy p2 8)
|
a = Num.bitwiseOr p1 (Num.shiftLeftBy p2 8)
|
||||||
b = Num.bitwiseOr (Num.shiftLeftBy p3 16) (Num.shiftLeftBy p4 24)
|
b = Num.bitwiseOr (Num.shiftLeftBy p3 16) (Num.shiftLeftBy p4 24)
|
||||||
|
|
||||||
|
|
@ -432,9 +436,9 @@ wyr4 = \list, index ->
|
||||||
wyr3 : List U8, Nat, Nat -> U64
|
wyr3 : List U8, Nat, Nat -> U64
|
||||||
wyr3 = \list, index, k ->
|
wyr3 = \list, index, k ->
|
||||||
# ((uint64_t)p[0])<<16)|(((uint64_t)p[k>>1])<<8)|p[k-1]
|
# ((uint64_t)p[0])<<16)|(((uint64_t)p[k>>1])<<8)|p[k-1]
|
||||||
p1 = List.getUnsafe list index |> Num.toU64
|
p1 = listGetUnsafe list index |> Num.toU64
|
||||||
p2 = List.getUnsafe list (Num.shiftRightZfBy k 1 |> Num.addWrap index) |> Num.toU64
|
p2 = listGetUnsafe list (Num.shiftRightZfBy k 1 |> Num.addWrap index) |> Num.toU64
|
||||||
p3 = List.getUnsafe list (Num.subWrap k 1 |> Num.addWrap index) |> Num.toU64
|
p3 = listGetUnsafe list (Num.subWrap k 1 |> Num.addWrap index) |> Num.toU64
|
||||||
a = Num.bitwiseOr (Num.shiftLeftBy p1 16) (Num.shiftLeftBy p2 8)
|
a = Num.bitwiseOr (Num.shiftLeftBy p1 16) (Num.shiftLeftBy p2 8)
|
||||||
|
|
||||||
Num.bitwiseOr a p3
|
Num.bitwiseOr a p3
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,6 @@ interface List
|
||||||
reserve,
|
reserve,
|
||||||
walkBackwardsUntil,
|
walkBackwardsUntil,
|
||||||
countIf,
|
countIf,
|
||||||
getUnsafe,
|
|
||||||
]
|
]
|
||||||
imports [
|
imports [
|
||||||
Bool.{ Bool, Eq },
|
Bool.{ Bool, Eq },
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ macro_rules! map_symbol_to_lowlevel_and_arity {
|
||||||
// Below, we explicitly handle some exceptions to the pattern where a lowlevel maps
|
// Below, we explicitly handle some exceptions to the pattern where a lowlevel maps
|
||||||
// directly to a symbol. If you are unsure if your lowlevel is an exception, assume
|
// directly to a symbol. If you are unsure if your lowlevel is an exception, assume
|
||||||
// that it isn't and just see if that works.
|
// that it isn't and just see if that works.
|
||||||
|
#[allow(unreachable_patterns)] // multiple symbols can map to one low-level
|
||||||
match lowlevel {
|
match lowlevel {
|
||||||
$(
|
$(
|
||||||
LowLevel::$lowlevel => Symbol::$symbol,
|
LowLevel::$lowlevel => Symbol::$symbol,
|
||||||
|
|
@ -144,6 +145,8 @@ map_symbol_to_lowlevel_and_arity! {
|
||||||
ListSwap; LIST_SWAP; 3,
|
ListSwap; LIST_SWAP; 3,
|
||||||
ListGetCapacity; LIST_CAPACITY; 1,
|
ListGetCapacity; LIST_CAPACITY; 1,
|
||||||
|
|
||||||
|
ListGetUnsafe; DICT_LIST_GET_UNSAFE; 2,
|
||||||
|
|
||||||
NumAdd; NUM_ADD; 2,
|
NumAdd; NUM_ADD; 2,
|
||||||
NumAddWrap; NUM_ADD_WRAP; 2,
|
NumAddWrap; NUM_ADD_WRAP; 2,
|
||||||
NumAddChecked; NUM_ADD_CHECKED_LOWLEVEL; 2,
|
NumAddChecked; NUM_ADD_CHECKED_LOWLEVEL; 2,
|
||||||
|
|
|
||||||
|
|
@ -1433,6 +1433,8 @@ define_builtins! {
|
||||||
15 DICT_WITH_CAPACITY: "withCapacity"
|
15 DICT_WITH_CAPACITY: "withCapacity"
|
||||||
16 DICT_CAPACITY: "capacity"
|
16 DICT_CAPACITY: "capacity"
|
||||||
17 DICT_UPDATE: "update"
|
17 DICT_UPDATE: "update"
|
||||||
|
|
||||||
|
18 DICT_LIST_GET_UNSAFE: "listGetUnsafe"
|
||||||
}
|
}
|
||||||
9 SET: "Set" => {
|
9 SET: "Set" => {
|
||||||
0 SET_SET: "Set" exposed_type=true // the Set.Set type alias
|
0 SET_SET: "Set" exposed_type=true // the Set.Set type alias
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue