Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NFData PersistValue #1440

Merged
merged 3 commits into from
Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions persistent/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog for persistent

## 2.14.4.0

* [#1440](https://github.com/yesodweb/persistent/pull/1440)
* Defined NFData PersistValue

## 2.14.3.2

* [#1446](https://github.com/yesodweb/persistent/pull/1446)
Expand Down
22 changes: 22 additions & 0 deletions persistent/Database/Persist/PersistValue.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Database.Persist.PersistValue
, LiteralType(..)
) where

import Control.DeepSeq
import qualified Data.ByteString.Base64 as B64
import qualified Data.Text.Encoding as TE
import qualified Data.ByteString.Char8 as BS8
Expand Down Expand Up @@ -70,6 +71,27 @@ data PersistValue
-- @since 2.12.0.0
deriving (Show, Read, Eq, Ord)

-- |
-- @since 2.14.4.0
instance NFData PersistValue where
avieth marked this conversation as resolved.
Show resolved Hide resolved
rnf val = case val of
PersistText txt -> rnf txt
PersistByteString bs -> rnf bs
PersistInt64 i -> rnf i
PersistDouble d -> rnf d
PersistRational q -> rnf q
PersistBool b -> rnf b
PersistDay d -> rnf d
PersistTimeOfDay t -> rnf t
PersistUTCTime t -> rnf t
PersistNull -> ()
PersistList vals -> rnf vals
PersistMap vals -> rnf vals
PersistObjectId bs -> rnf bs
PersistArray vals -> rnf vals
PersistLiteral_ ty bs -> ty `seq` rnf bs


-- | A type that determines how a backend should handle the literal.
--
-- @since 2.12.0.0
Expand Down
2 changes: 2 additions & 0 deletions persistent/persistent.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ library
, bytestring >= 0.10
, conduit >= 1.2.12
, containers >= 0.5
, deepseq
, fast-logger >= 2.4
, http-api-data >= 0.3
, lift-type >= 0.1.0.0 && < 0.2.0.0
Expand Down Expand Up @@ -127,6 +128,7 @@ test-suite test
, bytestring
, conduit
, containers
, deepseq
, fast-logger
, hspec >= 2.4
, http-api-data
Expand Down