diff options
author | Herbert Valerio Riedel <hvr@gnu.org> | 2017-10-16 21:01:57 +0200 |
---|---|---|
committer | Herbert Valerio Riedel <hvr@gnu.org> | 2017-10-16 21:09:06 +0200 |
commit | e3ba26f8b49700b41ff4672f3f7f6a4e453acdcc (patch) | |
tree | 26880006ca2615143f18349dcf892aa25e3fe29b /rts/RtsSymbols.c | |
parent | add85cc2a3ec0bda810dca2a35264308ffaab069 (diff) | |
download | haskell-e3ba26f8b49700b41ff4672f3f7f6a4e453acdcc.tar.gz |
Implement new `compareByteArrays#` primop
The new primop
compareByteArrays# :: ByteArray# -> Int# {- offset -}
-> ByteArray# -> Int# {- offset -}
-> Int# {- length -}
-> Int#
allows to compare the subrange of the first `ByteArray#` to
the (same-length) subrange of the second `ByteArray#` and returns a
value less than, equal to, or greater than zero if the range is found,
respectively, to be byte-wise lexicographically less than, to match,
or be greater than the second range.
Under the hood, the new primop is implemented in terms of the standard
ISO C `memcmp(3)` function. It is currently an out-of-line primop but
work is underway to optimise this into an inline primop for a future
follow-up Differential (see D4091).
This primop has applications in packages like `text`, `text-short`,
`bytestring`, `text-containers`, `primitive`, etc. which currently
have to incur the overhead of an ordinary FFI call to directly or
indirectly invoke `memcmp(3)` as well has having to deal with some
`unsafePerformIO`-variant.
While at it, this also improves the documentation for the existing
`copyByteArray#` primitive which has a non-trivial type-signature
that significantly benefits from a more explicit description of its
arguments.
Reviewed By: bgamari
Differential Revision: https://phabricator.haskell.org/D4090
Diffstat (limited to 'rts/RtsSymbols.c')
-rw-r--r-- | rts/RtsSymbols.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/rts/RtsSymbols.c b/rts/RtsSymbols.c index a696f44476..1ac143be95 100644 --- a/rts/RtsSymbols.c +++ b/rts/RtsSymbols.c @@ -674,6 +674,7 @@ SymI_HasProto(stg_casMutVarzh) \ SymI_HasProto(stg_newPinnedByteArrayzh) \ SymI_HasProto(stg_newAlignedPinnedByteArrayzh) \ + SymI_HasProto(stg_compareByteArrayszh) \ SymI_HasProto(stg_isByteArrayPinnedzh) \ SymI_HasProto(stg_isMutableByteArrayPinnedzh) \ SymI_HasProto(stg_shrinkMutableByteArrayzh) \ |