Skip to content

Commit

Permalink
Merge pull request #6 from haskell-works/fromByteString-alternatives
Browse files Browse the repository at this point in the history
fromByteString alternatives
  • Loading branch information
newhoggy authored Jul 8, 2019
2 parents ec7cacd + 52905ab commit ae574ab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/HaskellWorks/Data/Json/Standard/Cursor/Fast.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module HaskellWorks.Data.Json.Standard.Cursor.Fast
( Cursor
, fromByteString
, fromByteStringViaBlanking
, fromByteStringViaSimd
, fromForeignRegion
, fromString
, fromBsIbBp
Expand Down Expand Up @@ -38,8 +40,22 @@ fromBsIbBp bs ibBp = GenericCursor
}
where J.IbBp ibPart bpPart = ibBp

-- | Load a 'Cursor' from a 'ByteString'
fromByteString :: BS.ByteString -> Cursor
fromByteString bs = fromBsIbBp bs (J.slowToIbBp bs)
fromByteString = fromByteStringViaBlanking
{-# DEPRECATED fromByteString "Use one of the other fromByteString* functions" #-}

-- | Load a 'Cursor' from a 'ByteString' via the blanking process.
-- This has reasonable performance, but uses a lot of memory due to
-- the lack of streaming
fromByteStringViaBlanking :: BS.ByteString -> Cursor
fromByteStringViaBlanking bs = fromBsIbBp bs (J.slowToIbBp bs)

-- | Load a 'Cursor' from a 'ByteString' via the blanking via `simd`
-- This has fast performance and streaming, but is only available
-- recent x86 platforms
fromByteStringViaSimd :: BS.ByteString -> Cursor
fromByteStringViaSimd jsonBs = fromBsIbBp jsonBs (simdToIbBp jsonBs)

fromForeignRegion :: F.ForeignRegion -> Cursor
fromForeignRegion (fptr, offset, size) = fromByteString (BSI.fromForeignPtr (castForeignPtr fptr) offset size)
Expand Down
2 changes: 1 addition & 1 deletion src/HaskellWorks/Data/Json/Standard/Cursor/Load/Cursor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import qualified HaskellWorks.Data.Json.Standard.Cursor.Fast as FAST
loadCursor :: String -> IO FAST.Cursor
loadCursor path = do
bs <- BS.mmap path
let !cursor = FAST.fromByteString bs
let !cursor = FAST.fromByteStringViaBlanking bs
return cursor

loadCursorWithIndex :: String -> IO (GenericCursor BSI.ByteString (DVS.Vector Word64) (SimpleBalancedParens (DVS.Vector Word64)))
Expand Down

0 comments on commit ae574ab

Please sign in to comment.