Skip to content

Commit

Permalink
Clarify documentation of 'customStrategy' based on haskell#690
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgundry committed Sep 19, 2024
1 parent 378d4c3 commit 86a3c35
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions Data/ByteString/Builder/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1060,11 +1060,20 @@ data AllocationStrategy = AllocationStrategy
{-# INLINE customStrategy #-}
customStrategy
:: (Maybe (Buffer, Int) -> IO Buffer)
-- ^ Buffer allocation function. If 'Nothing' is given, then a new first
-- buffer should be allocated. If @'Just' (oldBuf, minSize)@ is given,
-- then a buffer with minimal size @minSize@ must be returned. The
-- strategy may reuse the @oldBuf@, if it can guarantee that this
-- referentially transparent and @oldBuf@ is large enough.
-- ^ Buffer allocation function.
--
-- * If 'Nothing' is given, then a new first buffer should be allocated.
--
-- * If @'Just' (oldBuf, minSize)@ is given, then a buffer with minimal
-- size @minSize@ must be returned. The strategy may reuse @oldBuf@ only if
-- @oldBuf@ is large enough and the consumer can guarantee that this will
-- not result in a violation of referential transparency.
--
-- /Warning:/ for multithreaded programs, it is generally unsafe to reuse
-- buffers when using the consumers of 'Builder' in this package. For
-- example, if 'toLazyByteStringWith' is called with an
-- 'AllocationStrategy' that reuses buffers, evaluating the result by
-- multiple threads simultaneously may lead to corrupted output.
-> Int
-- ^ Default buffer size.
-> (Int -> Int -> Bool)
Expand Down

0 comments on commit 86a3c35

Please sign in to comment.