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 /includes | |
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 'includes')
-rw-r--r-- | includes/stg/MiscClosures.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/includes/stg/MiscClosures.h b/includes/stg/MiscClosures.h index 76cfbd6c8c..66e26545f8 100644 --- a/includes/stg/MiscClosures.h +++ b/includes/stg/MiscClosures.h @@ -351,6 +351,7 @@ RTS_FUN_DECL(stg_casArrayzh); RTS_FUN_DECL(stg_newByteArrayzh); RTS_FUN_DECL(stg_newPinnedByteArrayzh); RTS_FUN_DECL(stg_newAlignedPinnedByteArrayzh); +RTS_FUN_DECL(stg_compareByteArrayszh); RTS_FUN_DECL(stg_isByteArrayPinnedzh); RTS_FUN_DECL(stg_isMutableByteArrayPinnedzh); RTS_FUN_DECL(stg_shrinkMutableByteArrayzh); |