Skip to content

Commit

Permalink
refactor(journal): use bulk copy in getByteString
Browse files Browse the repository at this point in the history
Thanks Daniel
  • Loading branch information
symbiont-stevan-andjelkovic committed Dec 30, 2021
1 parent e05a081 commit 0e8a33d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/journal/src/Journal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ defaultOptions = Options 1024 (64 * 1024)

allocateJournal :: FilePath -> Options -> IO ()
allocateJournal = undefined
-- System.Posix.Fcntl.fileAllocate

startJournal' :: FilePath -> Options -> IO Journal'
startJournal' fp (Options _ termLength) = do
Expand Down
4 changes: 1 addition & 3 deletions src/journal/src/Journal/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ tryClaim jour len = do
return (backPressureStatus position len)

calculatePositionLimit = undefined
backPressureStatus = undefined

newPosition :: Metadata -> Maybe TermOffset -> IO (Maybe Int64)
newPosition meta mResultingOffset =
Expand All @@ -139,8 +140,6 @@ newPosition meta mResultingOffset =
rotateTerm meta
return Nothing -- ADMIN_ACTION

backPressureStatus = undefined

fRAME_ALIGNMENT :: Int
fRAME_ALIGNMENT = 32

Expand Down Expand Up @@ -223,7 +222,6 @@ commit = undefined

abort = undefined


------------------------------------------------------------------------

claim :: Journal -> Int -> IO Int
Expand Down
11 changes: 8 additions & 3 deletions src/journal/src/Journal/Internal/ByteBuffer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,14 @@ putLazyByteString bb lbs = do
s' -> (# s', () #)

getByteString :: ByteBuffer -> Int -> IO BS.ByteString
getByteString bb len = do
bytes <- replicateM len (getByte bb)
return (BS.packBytes bytes)
getByteString bb len@(I# len#) = do
boundCheck bb (len - 1)
Position (I# offset#) <- readPosition bb
bs <- BS.create len $ \(Ptr addr#) -> IO $ \s ->
case copyMutableByteArrayToAddr# (bbData bb) offset# addr# len# s of
s' -> (# s', () #)
incrPosition bb len
return bs

getLazyByteString :: ByteBuffer -> Int -> IO LBS.ByteString
getLazyByteString bb len = do
Expand Down

0 comments on commit 0e8a33d

Please sign in to comment.