mirror of
https://github.com/status-im/nim-stew.git
synced 2025-01-25 03:20:26 +00:00
4e223b95a7
Looking at generated assembly, it turns out the optimizer is not smart enough to get rid of the loop - use `copyMem` instead. At least the compiler is smart enough to constant-propagate runtime endian direction, resolving the review comment. Also clarify why a minimum length is enfored - it could perhaps be revisited, but that would leave a slightly odd API. the `array` overloads are actually unnecessary with an optimizing compiler - as long as it can prove the length, any extra checks will go away on their own also add `initCopyFrom` * document optimizations
36 lines
957 B
Nim
36 lines
957 B
Nim
# stew
|
|
# Copyright 2018-2019 Status Research & Development GmbH
|
|
# Licensed under either of
|
|
#
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
|
#
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
{.used.}
|
|
|
|
import
|
|
std/unittest,
|
|
../stew/arrayops
|
|
|
|
suite "arrayops":
|
|
test "basic":
|
|
let
|
|
a = [byte 0, 1]
|
|
b = [byte 4, 5]
|
|
|
|
check:
|
|
(a and b) == [a[0] and b[0], a[1] and b[1]]
|
|
(a or b) == [a[0] or b[0], a[1] or b[1]]
|
|
(a xor b) == [a[0] xor b[0], a[1] xor b[1]]
|
|
(not a) == [not a[0], not a[1]]
|
|
|
|
test "copyFrom":
|
|
let
|
|
a = [byte 4, 5]
|
|
|
|
check:
|
|
array[4, byte].initCopyFrom(a) == [byte 4, 5, 0, 0]
|
|
array[1, byte].initCopyFrom(a) == [byte 4]
|
|
array[2, byte].initCopyFrom(a) == [byte 4, 5]
|