double buffer size, rather than increasing it by a constant factor, on every iteration in builder run function
This commit is contained in:
parent
01bf4655e3
commit
e0b9d744cf
1 changed files with 5 additions and 4 deletions
|
@ -92,8 +92,9 @@ import qualified Data.Vector as V
|
||||||
import qualified Data.ByteArray.Builder.Bounded as Bounded
|
import qualified Data.ByteArray.Builder.Bounded as Bounded
|
||||||
import qualified Data.ByteArray.Builder.Bounded.Unsafe as UnsafeBounded
|
import qualified Data.ByteArray.Builder.Bounded.Unsafe as UnsafeBounded
|
||||||
|
|
||||||
-- | Run a builder. An accurate size hint is important for good performance.
|
-- | Run a builder. An accurate size hint is important for
|
||||||
-- The size hint should be slightly larger than the actual size.
|
-- good performance. The size hint should be slightly greater
|
||||||
|
-- than or equal to the actual size.
|
||||||
run ::
|
run ::
|
||||||
Int -- ^ Hint for upper bound on size
|
Int -- ^ Hint for upper bound on size
|
||||||
-> Builder -- ^ Builder
|
-> Builder -- ^ Builder
|
||||||
|
@ -102,11 +103,11 @@ run hint b = runByteArrayST $ do
|
||||||
let go !n = do
|
let go !n = do
|
||||||
arr <- PM.newByteArray n
|
arr <- PM.newByteArray n
|
||||||
pasteST b (MutableBytes arr 0 n) >>= \case
|
pasteST b (MutableBytes arr 0 n) >>= \case
|
||||||
Nothing -> go (n + 64)
|
Nothing -> go (n + n + 16)
|
||||||
Just len -> do
|
Just len -> do
|
||||||
shrinkMutableByteArray arr len
|
shrinkMutableByteArray arr len
|
||||||
PM.unsafeFreezeByteArray arr
|
PM.unsafeFreezeByteArray arr
|
||||||
go (max hint 1)
|
go (max hint 16)
|
||||||
|
|
||||||
-- | Variant of 'pasteArrayST' that runs in 'IO'.
|
-- | Variant of 'pasteArrayST' that runs in 'IO'.
|
||||||
pasteArrayIO ::
|
pasteArrayIO ::
|
||||||
|
|
Loading…
Reference in a new issue