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

Yet another omnibus #355

Merged
merged 7 commits into from
Jul 19, 2021
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
2 changes: 0 additions & 2 deletions benchmarks/haskell/Benchmarks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import qualified Benchmarks.EncodeUtf8 as EncodeUtf8
import qualified Benchmarks.Equality as Equality
import qualified Benchmarks.FileRead as FileRead
import qualified Benchmarks.FoldLines as FoldLines
import qualified Benchmarks.Mul as Mul
import qualified Benchmarks.Multilang as Multilang
import qualified Benchmarks.Pure as Pure
import qualified Benchmarks.ReadNumbers as ReadNumbers
Expand Down Expand Up @@ -77,7 +76,6 @@ main = do
, env (Equality.initEnv (tf "japanese.txt")) Equality.benchmark
, FileRead.benchmark (tf "russian.txt")
, FoldLines.benchmark (tf "russian.txt")
, env Mul.initEnv Mul.benchmark
, Multilang.benchmark
, bgroup "Pure"
[ env (Pure.initEnv (tf "tiny.txt")) (Pure.benchmark "tiny")
Expand Down
146 changes: 0 additions & 146 deletions benchmarks/haskell/Benchmarks/Mul.hs

This file was deleted.

4 changes: 2 additions & 2 deletions src/Data/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ takeWhileEnd p t@(Text arr off len) = loop (len-1) len
where loop !i !l | l <= 0 = t
| p c = loop (i+d) (l+d)
| otherwise = text arr (off+l) (len-l)
where (c,d) = reverseIter t i
where Iter c d = reverseIter t i
{-# INLINE [1] takeWhileEnd #-}

-- | /O(n)/ 'dropWhile' @p@ @t@ returns the suffix remaining after
Expand All @@ -1189,7 +1189,7 @@ dropWhileEnd p t@(Text arr off len) = loop (len-1) len
where loop !i !l | l <= 0 = empty
| p c = loop (i+d) (l+d)
| otherwise = Text arr off l
where (c,d) = reverseIter t i
where Iter c d = reverseIter t i
{-# INLINE [1] dropWhileEnd #-}

-- | /O(n)/ 'dropAround' @p@ @t@ returns the substring remaining after
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Text/Lazy/Builder/RealFloat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ data FPFormat = Exponent
| Generic
-- ^ Use decimal notation for values between @0.1@ and
-- @9,999,999@, and scientific notation otherwise.
deriving (Enum, Read, Show)
deriving (Enum, Read, Show, Bounded)

-- | Show a signed 'RealFloat' value to full precision,
-- using standard decimal notation for arguments whose absolute value lies
Expand Down
6 changes: 3 additions & 3 deletions src/Data/Text/Unsafe.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ iter_ (Text arr off _len) i | m < 0xD800 || m > 0xDBFF = 1
-- | /O(1)/ Iterate one step backwards through a UTF-16 array,
-- returning the current character and the delta to add (i.e. a
-- negative number) to give the next offset to iterate at.
reverseIter :: Text -> Int -> (Char,Int)
reverseIter :: Text -> Int -> Iter
reverseIter (Text arr off _len) i
| m < 0xDC00 || m > 0xDFFF = (unsafeChr m, -1)
| otherwise = (chr2 n m, -2)
| m < 0xDC00 || m > 0xDFFF = Iter (unsafeChr m) (-1)
| otherwise = Iter (chr2 n m) (-2)
where m = A.unsafeIndex arr j
n = A.unsafeIndex arr k
j = off + i
Expand Down
26 changes: 15 additions & 11 deletions tests/Tests/Properties/Basics.hs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
-- | Test basic text functions

{-# LANGUAGE ViewPatterns #-}

{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
module Tests.Properties.Basics
( testBasics
) where

import Control.Arrow (first, second)
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.QuickCheck (testProperty)
import Test.Tasty.QuickCheck (testProperty, applyFun)
import Tests.QuickCheckUtils
import Text.Show.Functions ()
import qualified Data.List as L
import qualified Data.Text as T
import qualified Data.Text.Internal.Fusion as S
Expand All @@ -19,7 +20,8 @@ import qualified Data.Text.Lazy as TL

s_cons x = (x:) `eqP` (unpackS . S.cons x)
s_cons_s x = (x:) `eqP` (unpackS . S.unstream . S.cons x)
sf_cons p x = ((x:) . L.filter p) `eqP` (unpackS . S.cons x . S.filter p)
sf_cons (applyFun -> p) x
= ((x:) . L.filter p) `eqP` (unpackS . S.cons x . S.filter p)
t_cons x = (x:) `eqP` (unpackS . T.cons x)
tl_cons x = (x:) `eqP` (unpackS . TL.cons x)
t_length_cons x = (L.length . (x:)) `eqP` (T.length . T.cons x)
Expand All @@ -34,15 +36,17 @@ tl_length_snoc x = (L.genericLength . (++ [x])) `eqP` (TL.length . flip TL.snoc
s_append s = (s++) `eqP` (unpackS . S.append (S.streamList s))
s_append_s s = (s++) `eqP`
(unpackS . S.unstream . S.append (S.streamList s))
sf_append p s = (L.filter p s++) `eqP`
sf_append (applyFun -> p) s
= (L.filter p s++) `eqP`
(unpackS . S.append (S.filter p $ S.streamList s))
t_append s = (s++) `eqP` (unpackS . T.append (packS s))

uncons (x:xs) = Just (x,xs)
uncons _ = Nothing

s_uncons = uncons `eqP` (fmap (second unpackS) . S.uncons)
sf_uncons p = (uncons . L.filter p) `eqP`
sf_uncons (applyFun -> p)
= (uncons . L.filter p) `eqP`
(fmap (second unpackS) . S.uncons . S.filter p)
t_uncons = uncons `eqP` (fmap (second unpackS) . T.uncons)
tl_uncons = uncons `eqP` (fmap (second unpackS) . TL.uncons)
Expand All @@ -54,29 +58,29 @@ t_unsnoc = unsnoc `eqP` (fmap (first unpackS) . T.unsnoc)
tl_unsnoc = unsnoc `eqP` (fmap (first unpackS) . TL.unsnoc)

s_head = head `eqP` S.head
sf_head p = (head . L.filter p) `eqP` (S.head . S.filter p)
sf_head (applyFun -> p) = (head . L.filter p) `eqP` (S.head . S.filter p)
t_head = head `eqP` T.head
tl_head = head `eqP` TL.head
s_last = last `eqP` S.last
sf_last p = (last . L.filter p) `eqP` (S.last . S.filter p)
sf_last (applyFun -> p) = (last . L.filter p) `eqP` (S.last . S.filter p)
t_last = last `eqP` T.last
tl_last = last `eqP` TL.last
s_tail = tail `eqP` (unpackS . S.tail)
s_tail_s = tail `eqP` (unpackS . S.unstream . S.tail)
sf_tail p = (tail . L.filter p) `eqP` (unpackS . S.tail . S.filter p)
sf_tail (applyFun -> p) = (tail . L.filter p) `eqP` (unpackS . S.tail . S.filter p)
t_tail = tail `eqP` (unpackS . T.tail)
tl_tail = tail `eqP` (unpackS . TL.tail)
s_init = init `eqP` (unpackS . S.init)
s_init_s = init `eqP` (unpackS . S.unstream . S.init)
sf_init p = (init . L.filter p) `eqP` (unpackS . S.init . S.filter p)
sf_init (applyFun -> p) = (init . L.filter p) `eqP` (unpackS . S.init . S.filter p)
t_init = init `eqP` (unpackS . T.init)
tl_init = init `eqP` (unpackS . TL.init)
s_null = null `eqP` S.null
sf_null p = (null . L.filter p) `eqP` (S.null . S.filter p)
sf_null (applyFun -> p) = (null . L.filter p) `eqP` (S.null . S.filter p)
t_null = null `eqP` T.null
tl_null = null `eqP` TL.null
s_length = length `eqP` S.length
sf_length p = (length . L.filter p) `eqP` (S.length . S.filter p)
sf_length (applyFun -> p) = (length . L.filter p) `eqP` (S.length . S.filter p)
sl_length = (fromIntegral . length) `eqP` SL.length
t_length = length `eqP` T.length
tl_length = L.genericLength `eqP` TL.length
Expand Down
9 changes: 4 additions & 5 deletions tests/Tests/Properties/Builder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Test.QuickCheck
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.QuickCheck (testProperty)
import Tests.QuickCheckUtils
import Text.Show.Functions ()
import qualified Data.List as L
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.Builder as TB
Expand Down Expand Up @@ -54,10 +53,10 @@ tb_decimal_word16 (a::Word16) = tb_decimal a
tb_decimal_word32 (a::Word32) = tb_decimal a
tb_decimal_word64 (a::Word64) = tb_decimal a

tb_decimal_big_int (BigBounded (a::Int)) = tb_decimal a
tb_decimal_big_int64 (BigBounded (a::Int64)) = tb_decimal a
tb_decimal_big_word (BigBounded (a::Word)) = tb_decimal a
tb_decimal_big_word64 (BigBounded (a::Word64)) = tb_decimal a
tb_decimal_big_int (Large (a::Int)) = tb_decimal a
tb_decimal_big_int64 (Large (a::Int64)) = tb_decimal a
tb_decimal_big_word (Large (a::Word)) = tb_decimal a
tb_decimal_big_word64 (Large (a::Word64)) = tb_decimal a

tb_hex :: (Integral a, Show a) => a -> Property
tb_hex = (TB.toLazyText . TB.hexadecimal) `eq` (TL.pack . flip showHex "")
Expand Down
Loading