diff options
author | Isaac Dupree <id@isaac.cedarswampstudios.org> | 2007-08-07 00:12:48 +0000 |
---|---|---|
committer | Isaac Dupree <id@isaac.cedarswampstudios.org> | 2007-08-07 00:12:48 +0000 |
commit | 55551ce576db8530e305e552945a58cc070aa98c (patch) | |
tree | 6b3aa5dabdb0f022377307a00ef07546bb95f468 /compiler/utils/FastString.lhs | |
parent | a5e533a6d23eed8a8f14314d54fd727b8023edf9 (diff) | |
download | haskell-55551ce576db8530e305e552945a58cc070aa98c.tar.gz |
more cmpFS refactoring
Diffstat (limited to 'compiler/utils/FastString.lhs')
-rw-r--r-- | compiler/utils/FastString.lhs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/compiler/utils/FastString.lhs b/compiler/utils/FastString.lhs index 637ef0cf72..ffe10c3a02 100644 --- a/compiler/utils/FastString.lhs +++ b/compiler/utils/FastString.lhs @@ -129,15 +129,17 @@ instance Show FastString where cmpFS :: FastString -> FastString -> Ordering cmpFS (FastString u1 l1 _ buf1 _) (FastString u2 l2 _ buf2 _) = if u1 == u2 then EQ else - let l = if l1 <= l2 then l1 else l2 in - inlinePerformIO $ - withForeignPtr buf1 $ \p1 -> - withForeignPtr buf2 $ \p2 -> do - res <- memcmp p1 p2 l - return $ case compare res 0 of - LT -> LT - EQ -> compare l1 l2 - GT -> GT + case unsafeMemcmp buf1 buf2 (min l1 l2) `compare` 0 of + LT -> LT + EQ -> compare l1 l2 + GT -> GT + +unsafeMemcmp :: ForeignPtr a -> ForeignPtr b -> Int -> Int +unsafeMemcmp buf1 buf2 l = + inlinePerformIO $ + withForeignPtr buf1 $ \p1 -> + withForeignPtr buf2 $ \p2 -> + memcmp p1 p2 l #ifndef __HADDOCK__ foreign import ccall unsafe "ghc_memcmp" |