Open archaephyrryx opened 4 years ago
The implementation of elemIndexEnd
was recently discussed here: https://github.com/haskell/bytestring/pull/155#issuecomment-628619601 It seems that thanks to inlining there is no performance penalty.
AFAIU Windows systems do not provide memrchr
, so the only option to remain cross-platform is to implement memrchr
in cbits
. I do not mind against such approach, if supported by benchmarks.
The current implementations of the
elemIndexEnd
function in modulesData.ByteString
andData.ByteString.Lazy
are uniformly defined asfindIndexEnd . (==)
(theChar8
version merely invokes the strict bytestring definition after converting fromChar
toWord8
).This seems counterintuitive when compared with
elemIndex
, which is more optimized thanfindIndex
through the use of thememchr
C FFI call to avoid costly byte-by-byte predicate testing.There exists a GNU extension for
string.h
that defines an operationmemrchr
that performs a similar operation tomemchr
but returns the final occurrence of a byte rather than the first, which could be used when available. Even without such platform-specific optimizations, it should still be possible to either add amemrchr
-like function to the cbits code.Even without FFI calls,
elemIndexEnd
could use the same logic asfindIndexEnd
and perform a byte-by-byte direct equality test at least as efficiently asfindIndexEnd . (==)
, but without the indirection.