2019-09-20 14:01:32 +00:00
|
|
|
import ../ptrops
|
|
|
|
export ptrops
|
|
|
|
|
2021-12-02 15:24:02 +00:00
|
|
|
proc baseAddr*[T](x: openArray[T]): pointer = cast[pointer](x)
|
2019-07-06 18:45:27 +00:00
|
|
|
|
2019-07-30 23:31:56 +00:00
|
|
|
# Please note that we use templates here on purpose.
|
|
|
|
# As much as I believe in the power of optimizing compilers, it turned
|
|
|
|
# out that the use of forced inlining with templates still creates a
|
|
|
|
# significant difference in the release builds of nim-faststreams
|
|
|
|
|
2019-09-20 14:01:32 +00:00
|
|
|
template shift*(p: pointer, delta: int): pointer {.deprecated: "use ptrops".} =
|
|
|
|
p.offset(delta)
|
2019-07-06 18:45:27 +00:00
|
|
|
|
2019-09-20 14:01:32 +00:00
|
|
|
template shift*[T](p: ptr T, delta: int): ptr T {.deprecated: "use ptrops".} =
|
|
|
|
p.offset(delta)
|
2019-08-06 18:02:03 +00:00
|
|
|
|
2020-05-12 19:59:46 +00:00
|
|
|
template makeOpenArray*[T](p: ptr T, len: Natural): auto =
|
|
|
|
toOpenArray(cast[ptr UncheckedArray[T]](p), 0, len - 1)
|
2019-07-06 18:45:27 +00:00
|
|
|
|
2020-05-12 19:59:46 +00:00
|
|
|
template makeOpenArray*(p: pointer, T: type, len: Natural): auto =
|
|
|
|
toOpenArray(cast[ptr UncheckedArray[T]](p), 0, len - 1)
|
2019-07-06 18:45:27 +00:00
|
|
|
|