- unsafePerformIO (
- _casm_ ``%r=(int)strncmp((char *)%0+(int)%1,%2,%3); ''
- (ByteArray bottom b2#)
- (I# start#)
- (A# a#)
- (I# len#) >>= \ (I# x#) ->
- return (x# ==# 0#))
- where
- bottom :: (Int,Int)
- bottom = error "eqCharStrPrefixBA"
-
-eqStrPrefixFO :: ForeignObj# -> ByteArray# -> Int# -> Int# -> Bool
-eqStrPrefixFO fo# barr# start# len# =
- unsafePerformIO (
- _casm_ ``%r=(int)strncmp((char *)%0+(int)%1,%2,%3); ''
- (ForeignObj fo#)
- (I# start#)
- (ByteArray bottom barr#)
- (I# len#) >>= \ (I# x#) ->
- return (x# ==# 0#))
- where
- bottom :: (Int,Int)
- bottom = error "eqStrPrefixFO"
+ inlinePerformIO $ do
+ x <- memcmp_baoff b2# (I# start#) a# (I# len#)
+ return (x == 0)
+#endif
+\end{code}
+
+\begin{code}
+-- Just like unsafePerformIO, but we inline it. This is safe when
+-- there are no side effects, and improves performance.
+{-# INLINE inlinePerformIO #-}
+inlinePerformIO :: IO a -> a
+inlinePerformIO (IO m) = case m realWorld# of (# _, r #) -> r
+
+#if __GLASGOW_HASKELL__ <= 408
+strLength (Ptr a#) = ghc_strlen a#
+foreign import ccall unsafe "ghc_strlen"
+ ghc_strlen :: Addr# -> Int
+#else
+foreign import ccall unsafe "ghc_strlen"
+ strLength :: Ptr () -> Int
+#endif
+
+foreign import ccall unsafe "ghc_memcmp"
+ memcmp :: Addr# -> Addr# -> Int -> IO Int
+
+foreign import ccall unsafe "ghc_memcmp"
+ memcmp_ba :: Addr# -> ByteArray# -> Int -> IO Int
+
+foreign import ccall unsafe "ghc_memcmp_off"
+ memcmp_baoff :: ByteArray# -> Int -> Addr# -> Int -> IO Int
+
+foreign import ccall unsafe "ghc_memcmp_off"
+ memcmp_baoff_ba :: ByteArray# -> Int -> ByteArray# -> Int -> IO Int