diff options
author | NikitaVolkov <> | 2021-01-12 17:53:00 (GMT) |
---|---|---|
committer | hdiff <hdiff@hdiff.luite.com> | 2021-01-12 17:53:00 (GMT) |
commit | bda7d8a3736d413490aa15503b1744620245057a (patch) | |
tree | 03b4f3d4310100922ec6f97f833fc1b0d08c7eea | |
parent | 7efa43ffcc16ecda7f95c8d9129aab1599226ba7 (diff) |
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | cbits/json_allocation.c | 19 | ||||
-rw-r--r-- | demo/Main.hs | 4 | ||||
-rw-r--r-- | jsonifier.cabal | 4 | ||||
-rw-r--r-- | library/Jsonifier/Ffi.hs | 2 |
5 files changed, 21 insertions, 12 deletions
@@ -82,7 +82,7 @@ JSON from your domain model. {-# LANGUAGE OverloadedStrings, RecordWildCards #-} import qualified Jsonifier as J -import qualified Data.ByteString.Char8 as Char8ByteString +import qualified Data.ByteString.Char8 {-| @@ -91,7 +91,7 @@ Outputs the following: > {"name":"Metallica","genres":[{"name":"Metal"},{"name":"Rock"},{"name":"Blues"}]} -} main = - Char8ByteString.putStrLn (J.toByteString (artistJson metallica)) + Data.ByteString.Char8.putStrLn (J.toByteString (artistJson metallica)) metallica :: Artist metallica = diff --git a/cbits/json_allocation.c b/cbits/json_allocation.c index b66bb1e..201da1c 100644 --- a/cbits/json_allocation.c +++ b/cbits/json_allocation.c @@ -14,13 +14,9 @@ static const int allocation_by_septet[128] = int count_string_allocation ( const uint16_t *src_ptr, - size_t src_off, - size_t src_len + const uint16_t *end_ptr ) { - src_ptr += src_off; - const uint16_t *end_ptr = src_ptr + src_len; - size_t allocation = 0; while (src_ptr < end_ptr) { @@ -45,3 +41,16 @@ int count_string_allocation return allocation; } + +int count_string_allocation_off_len +( + const uint16_t *src_ptr, + size_t src_off, + size_t src_len +) +{ + src_ptr += src_off; + const uint16_t *end_ptr = src_ptr + src_len; + + return count_string_allocation(src_ptr, end_ptr); +} diff --git a/demo/Main.hs b/demo/Main.hs index 669ec28..8dd5399 100644 --- a/demo/Main.hs +++ b/demo/Main.hs @@ -1,7 +1,7 @@ {-# LANGUAGE OverloadedStrings, RecordWildCards #-} import qualified Jsonifier as J -import qualified Data.ByteString.Char8 as Char8ByteString +import qualified Data.ByteString.Char8 {-| @@ -10,7 +10,7 @@ Outputs the following: > {"name":"Metallica","genres":[{"name":"Metal"},{"name":"Rock"},{"name":"Blues"}]} -} main = - Char8ByteString.putStrLn (J.toByteString (artistJson metallica)) + Data.ByteString.Char8.putStrLn (J.toByteString (artistJson metallica)) metallica :: Artist metallica = diff --git a/jsonifier.cabal b/jsonifier.cabal index 85d746d..f50d508 100644 --- a/jsonifier.cabal +++ b/jsonifier.cabal @@ -1,5 +1,5 @@ name: jsonifier -version: 0.1.0.5 +version: 0.1.0.6 synopsis: Fast and simple JSON encoding toolkit description: Minimalistic library for encoding JSON directly to strict bytestring, @@ -42,7 +42,7 @@ library build-depends: base >=4.11 && <5, bytestring >=0.10.10 && <0.12, - ptr-poker >=0.1 && <0.2, + ptr-poker >=0.1.1.3 && <0.2, scientific >=0.3.6.2 && <0.4, text >=1 && <2 diff --git a/library/Jsonifier/Ffi.hs b/library/Jsonifier/Ffi.hs index 8d0eb71..dbef17f 100644 --- a/library/Jsonifier/Ffi.hs +++ b/library/Jsonifier/Ffi.hs @@ -7,7 +7,7 @@ import Foreign.C import GHC.Base (ByteArray#, MutableByteArray#) -foreign import ccall unsafe "static count_string_allocation" +foreign import ccall unsafe "static count_string_allocation_off_len" countStringAllocationSize :: ByteArray# -> CSize -> CSize -> IO CInt foreign import ccall unsafe "static encode_utf16_as_string" |