packages feed

symbolize 1.0.0.4 → 1.0.1.0

raw patch · 3 files changed

+39/−2 lines, 3 filesdep +binary

Dependencies added: binary

Files

CHANGELOG.md view
@@ -8,6 +8,11 @@  ## Unreleased +## 1.0.1.0++- Add `Data.Data` instance+- Add `Data.Binary` instance+ ## 1.0.0.4  - Minor documentation improvements
src/Symbolize.hs view
@@ -5,7 +5,7 @@ -- | Implementation of a global Symbol Table, with garbage collection. -- -- Symbols, also known as Atoms or Interned Strings, are a common technique--- to reduce memory usage and improve performance when using many small strings.+-- to reduce memory usage and improve performance when using many small strings: -- -- A Symbol represents a string (any `Textual`, so String, Text, ShortText, ByteString, ShortByteString, etc.) --@@ -164,6 +164,9 @@ import Text.Read (Lexeme (Ident), Read (..), lexP, parens, prec, readListPrecDefault) import Text.Read qualified import Prelude hiding (lookup)+import Data.Data qualified+import Data.Binary qualified+import Data.Text.Short (ShortText)  -- | A string-like type with O(1) equality and comparison. --@@ -392,3 +395,29 @@ textualFromBA# :: (Textual str) => ByteArray# -> str {-# INLINE textualFromBA# #-} textualFromBA# ba# = Textual.fromShortText (Text.Short.Unsafe.fromShortByteStringUnsafe (SBS ba#))++-- | This `Data` instance follows the same implementation as the one for +-- `Text` and `ShortText`: It pretends `Symbol` is a a collection holding a `[Char]`.+--+-- @since 1.0.1.0+instance Data.Data.Data Symbolize.Symbol where+  gfoldl f z txt = z (Symbolize.intern @String) `f` Symbolize.unintern @String txt+  toConstr _ = internConstr+  gunfold k z c = case Data.Data.constrIndex c of+    1 -> k (z (Symbolize.intern @String))+    _ -> error "gunfold"+  dataTypeOf _ = symbolDataType++symbolDataType :: Data.Data.DataType+symbolDataType = Data.Data.mkDataType "Symbolize.Symbol" [internConstr]++internConstr :: Data.Data.Constr+internConstr = Data.Data.mkConstr symbolDataType "intern" [] Data.Data.Prefix++-- | Uses the `ShortByteString` instance of `Textual` under the hood;+-- invalid UTF-8 is replaced by the Unicode replacement character.+--+--  @since 1.0.1.0+instance Data.Binary.Binary Symbol where+  put = Data.Binary.put . Symbolize.unintern @ShortByteString+  get = Symbolize.intern @ShortByteString <$> Data.Binary.get
symbolize.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           symbolize-version:        1.0.0.4+version:        1.0.1.0 synopsis:       Efficient global Symbol table, with Garbage Collection. description:    Symbols, also known as Atoms or Interned Strings, are a common technique                 to reduce memory usage and improve performance when using many small strings:@@ -70,6 +70,7 @@   ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints   build-depends:       base >=4.7 && <5+    , binary >=0.8.9 && <0.9     , bytestring >=0.11.0 && <0.13     , containers >=0.6.0 && <0.7     , deepseq >=1.4.0 && <1.6@@ -97,6 +98,7 @@   ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N   build-depends:       base >=4.7 && <5+    , binary >=0.8.9 && <0.9     , bytestring >=0.11.0 && <0.13     , containers >=0.6.0 && <0.7     , deepseq >=1.4.0 && <1.6@@ -130,6 +132,7 @@   build-depends:       async     , base >=4.7 && <5+    , binary >=0.8.9 && <0.9     , bytestring >=0.11.0 && <0.13     , containers >=0.6.0 && <0.7     , deepseq >=1.4.0 && <1.6