packages feed

vcache 0.2.0 → 0.2.1

raw patch · 4 files changed

+36/−18 lines, 4 files

Files

hsrc_lib/Database/VCache/VPut.hs view
@@ -15,11 +15,16 @@     , reserve, reserving, unsafePutWord8     , putByteString, putByteStringLazy     , putc++    , peekBufferSize+    , peekChildCount     ) where +import Control.Applicative import Data.Bits import Data.Char import Data.Word+import qualified Data.List as L import Foreign.Ptr (plusPtr,castPtr) import Foreign.Storable (Storable(..)) import Foreign.Marshal.Utils (copyBytes)@@ -221,4 +226,9 @@         x = fromIntegral (shiftR c 12 .&. 0x3f)         w = fromIntegral (shiftR c 18 .&. 0x7) ++-- | Obtain the total count of VRefs and PVars in the VPut buffer.+peekChildCount :: VPut Int+peekChildCount = L.length <$> peekChildren+{-# INLINE peekChildCount #-} 
hsrc_lib/Database/VCache/VPutAux.hs view
@@ -8,6 +8,9 @@     , putVarNat     , putVarInt     , putVarNatR++    , peekBufferSize+    , peekChildren     ) where  import Control.Applicative@@ -118,3 +121,22 @@ _putVarNatR n = putWord8 b >> _putVarNatR q where     b = 0x80 .|. (0x7f .&. fromIntegral n)     q = n `shiftR` 7++-- | Obtain the number of bytes output by this VPut effort so far.+-- This might be useful if you're breaking data structures up by their+-- serialization sizes. This does not include VRefs or PVars, only+-- raw binary data. See also peekChildCount.+peekBufferSize :: VPut Int+peekBufferSize = VPut $ \ s ->+    readIORef (vput_buffer s) >>= \ pStart ->+    let size = (vput_target s) `minusPtr` pStart in+    size `seq`+    return (VPutR size s)+{-# INLINE peekBufferSize #-}++peekChildren :: VPut [PutChild]+peekChildren = VPut $ \ s ->+    let r = vput_children s in+    return (VPutR r s)+{-# INLINE peekChildren #-}+
hsrc_lib/Database/VCache/VPutFini.hs view
@@ -36,26 +36,12 @@ -- and that this be applied before any hash functions. vputFini :: VPut () vputFini = do-    szStart <- getBufferSize-    lChildren <- listChildren+    szStart <- peekBufferSize+    lChildren <- peekChildren     putChildren lChildren-    szFini <- getBufferSize+    szFini <- peekBufferSize     putVarNatR (szFini - szStart)     -- shrinkBuffer--getBufferSize :: VPut Int-getBufferSize = VPut $ \ s ->-    readIORef (vput_buffer s) >>= \ pStart ->-    let size = (vput_target s) `minusPtr` pStart in-    size `seq`-    return (VPutR size s)-{-# INLINE getBufferSize #-}--listChildren :: VPut [PutChild]-listChildren = VPut $ \ s ->-    let r = vput_children s in-    return (VPutR r s)-{-# INLINE listChildren #-}  putChildren :: [PutChild] -> VPut () putChildren [] = return ()
vcache.cabal view
@@ -1,5 +1,5 @@ Name: vcache-Version: 0.2.0+Version: 0.2.1 Synopsis: large, persistent, memcached values and structure sharing for Haskell  Category: Database Description: