packages feed

ngx-export 0.6.1.1 → 0.7.0.0

raw patch · 3 files changed

+45/−28 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Changelog.md view
@@ -1,3 +1,10 @@+### 0.7.0.0++Further optimizations.++- Poke single-chunked lazy bytestrings directly into passed from Nginx buffers.+- Specialize polymorphic functions and inline trivial functions.+ ### 0.6.1.1  - Added *-Wno-incomplete-patterns* in *ghc-options* for older ghc versions.@@ -12,7 +19,7 @@  ### 0.6.0.0 -- Lazy bytestrings contents are no longer copied when passed back to nginx.+- Lazy bytestrings contents are no longer copied when passed back to Nginx.   Instead, they are passed directly along with a StablePtr to original   bytestrings. This must improve performance and lower memory consumption for   content handlers with large outputs.
NgxExport.hs view
@@ -70,9 +70,6 @@ pattern ToBool i <- (toBool -> i) {-# COMPLETE ToBool :: CUInt #-} -pattern EmptyLBS :: C8L.ByteString-pattern EmptyLBS <- (L.null -> True)- data NgxExport = SS            (String -> String)                | SSS           (String -> String -> String)                | SLS           ([String] -> String)@@ -299,7 +296,13 @@ safeMallocBytes :: Int -> IO (Ptr a) safeMallocBytes =     flip catchIOError (const $ return nullPtr) . mallocBytes+{-# INLINE safeMallocBytes #-} +safeNewCStringLen :: String -> IO CStringLen+safeNewCStringLen =+    flip catchIOError (const $ return (nullPtr, -1)) . newCStringLen+{-# INLINE safeNewCStringLen #-}+ peekNgxStringArrayLen :: Ptr NgxStrType -> Int -> IO [String] peekNgxStringArrayLen x n = sequence $     foldr (\k ->@@ -316,36 +319,43 @@  pokeCStringLen :: Storable a => CString -> a -> Ptr CString -> Ptr a -> IO () pokeCStringLen x n p s = poke p x >> poke s n+{-# SPECIALIZE INLINE+    pokeCStringLen :: CString -> CInt -> Ptr CString -> Ptr CInt ->IO () #-}+{-# SPECIALIZE INLINE+    pokeCStringLen :: CString -> CSize -> Ptr CString -> Ptr CSize ->IO () #-} -toBuffers :: L.ByteString -> IO (Ptr NgxStrType, Int)-toBuffers EmptyLBS =+toBuffers :: L.ByteString -> Ptr NgxStrType -> IO (Ptr NgxStrType, Int)+toBuffers (L.null -> True) _ =     return (nullPtr, 0)-toBuffers s = do-    t <- safeMallocBytes $-        L.foldlChunks (const . succ) 0 s * sizeOf (undefined :: NgxStrType)-    if t == nullPtr-        then return (nullPtr, -1)-        else (,) t <$>-                L.foldlChunks-                    (\a c -> do-                        off <- a-                        B.unsafeUseAsCStringLen c $-                            \(x, I l) -> pokeElemOff t off $ NgxStrType l x-                        return $ off + 1-                    ) (return 0) s+toBuffers s p = do+    let n = L.foldlChunks (const . succ) 0 s+    if n == 1+        then do+            B.unsafeUseAsCStringLen (head $ L.toChunks s) $+                \(x, I l) -> poke p $ NgxStrType l x+            return (p, 1)+        else do+            t <- safeMallocBytes $ n * sizeOf (undefined :: NgxStrType)+            if t == nullPtr+                then return (nullPtr, -1)+                else (,) t <$>+                        L.foldlChunks+                            (\a c -> do+                                off <- a+                                B.unsafeUseAsCStringLen c $+                                    \(x, I l) ->+                                        pokeElemOff t off $ NgxStrType l x+                                return $ off + 1+                            ) (return 0) s  pokeLazyByteString :: L.ByteString ->     Ptr (Ptr NgxStrType) -> Ptr CInt ->     Ptr (StablePtr L.ByteString) -> IO () pokeLazyByteString s p pl spd = do-    PtrLen t l <- toBuffers s-    poke p t >> poke pl l+    PtrLen t l <- peek p >>= toBuffers s+    when (l /= 1) (poke p t) >> poke pl l     when (t /= nullPtr) $ newStablePtr s >>= poke spd -safeNewCStringLen :: String -> IO CStringLen-safeNewCStringLen =-    flip catchIOError (const $ return (nullPtr, -1)) . newCStringLen- safeHandler :: Ptr CString -> Ptr CInt -> IO CUInt -> IO CUInt safeHandler p pl = handle $ \e -> do     PtrLen x l <- safeNewCStringLen $ show (e :: SomeException)@@ -489,8 +499,8 @@ handler f x (I n) p pl pct plct pst spd =     safeHandler pct pst $ do         (s, ct, I st) <- f <$> B.unsafePackCStringLen (x, n)-        PtrLen t l <- toBuffers s-        poke p t >> poke pl l+        PtrLen t l <- peek p >>= toBuffers s+        when (l /= 1) (poke p t) >> poke pl l         PtrLen sct lct <- newCStringLen ct         pokeCStringLen sct lct pct plct >> poke pst st         when (t /= nullPtr) $ newStablePtr s >>= poke spd
ngx-export.cabal view
@@ -1,5 +1,5 @@ name:                ngx-export-version:             0.6.1.1+version:             0.7.0.0 synopsis:            Helper module for Nginx haskell module description:         Helper module for         <http://github.com/lyokha/nginx-haskell-module Nginx haskell module>