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

Move deprecated modules to undeprecated hidden modules #213

Merged
merged 2 commits into from
Dec 3, 2023
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
8 changes: 4 additions & 4 deletions Generate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ main = do
,"import GHC.IO.Encoding.Failure ( CodingFailureMode(..) )"
,"import GHC.IO.Encoding.UTF16 ( mkUTF16le )"
,"import GHC.IO.Encoding.UTF8 ( mkUTF8 )"
,"import System.OsString.Internal.Types"
,"import System.OsPath.Encoding.Internal"
,"import System.OsString.Internal.Types.Hidden"
,"import System.OsPath.Encoding.Internal.Hidden"
,"import qualified Data.Char as C"
,"import qualified System.OsPath.Data.ByteString.Short as SBS"
,"import qualified System.OsPath.Data.ByteString.Short.Word16 as SBS16"
,"import qualified System.OsPath.Data.ByteString.Short.Hidden as SBS"
,"import qualified System.OsPath.Data.ByteString.Short.Word16.Hidden as SBS16"
,"import qualified System.FilePath.Windows as W"
,"import qualified System.FilePath.Posix as P"
#ifdef GHC_MAKE
Expand Down
6 changes: 3 additions & 3 deletions System/FilePath/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ import GHC.IO.Encoding.Failure ( CodingFailureMode(..) )
import GHC.IO.Encoding.UTF16 ( mkUTF16le )
import qualified GHC.Foreign as GHC
import Data.Word ( Word16 )
import System.OsPath.Data.ByteString.Short.Word16
import System.OsPath.Data.ByteString.Short ( packCStringLen )
import System.OsPath.Data.ByteString.Short.Word16.Hidden
import System.OsPath.Data.ByteString.Short.Hidden ( packCStringLen )
#define CHAR Word16
#define STRING ShortByteString
#define FILEPATH ShortByteString
Expand All @@ -148,7 +148,7 @@ import GHC.IO.Encoding.Failure ( CodingFailureMode(..) )
import qualified GHC.Foreign as GHC
import GHC.IO.Encoding.UTF8 ( mkUTF8 )
import Data.Word ( Word8 )
import System.OsPath.Data.ByteString.Short
import System.OsPath.Data.ByteString.Short.Hidden
#define CHAR Word8
#define STRING ShortByteString
#define FILEPATH ShortByteString
Expand Down
8 changes: 4 additions & 4 deletions System/OsPath/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ where

#ifdef WINDOWS
import System.OsPath.Types
import System.OsString.Windows as PS
import System.OsString.Windows.Hidden as PS
( unsafeFromChar
, toChar
, decodeUtf
Expand Down Expand Up @@ -141,7 +141,7 @@ import Language.Haskell.TH.Syntax

import GHC.IO.Encoding.UTF8 ( mkUTF8 )
import System.OsPath.Types
import System.OsString.Posix as PS
import System.OsString.Posix.Hidden as PS
( unsafeFromChar
, toChar
, decodeUtf
Expand Down Expand Up @@ -171,7 +171,7 @@ import System.OsPath.Internal as PS
)
import System.OsPath.Types
( OsPath )
import System.OsString ( unsafeFromChar, toChar )
import System.OsString.Internal.Hidden ( unsafeFromChar, toChar )

#if defined(mingw32_HOST_OS) || defined(__MINGW32__)
import qualified System.OsPath.Windows as C
Expand All @@ -182,7 +182,7 @@ import qualified System.OsPath.Posix as C
import Data.Bifunctor
( bimap )
#endif
import System.OsString.Internal.Types
import System.OsString.Internal.Types.Hidden


------------------------
Expand Down
17 changes: 1 addition & 16 deletions System/OsPath/Data/ByteString/Short.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NoImplicitPrelude #-}
-- |
-- Module : System.OsPath.Data.ByteString.Short
Expand Down Expand Up @@ -176,18 +175,4 @@ module System.OsPath.Data.ByteString.Short {-# DEPRECATED "Use System.OsString.D
useAsCStringLen,
) where

import Data.ByteString.Short.Internal
import System.OsPath.Data.ByteString.Short.Internal

import Prelude (Maybe(..), Ord(..), Num(..), ($), otherwise)
import Data.Word (Word8)

uncons2 :: ShortByteString -> Maybe (Word8, Word8, ShortByteString)
uncons2 = \sbs ->
let l = length sbs
nl = l - 2
in if | l <= 1 -> Nothing
| otherwise -> let h = indexWord8Array (asBA sbs) 0
h' = indexWord8Array (asBA sbs) 1
t = create nl $ \mba -> copyByteArray (asBA sbs) 1 mba 0 nl
in Just (h, h', t)
import System.OsPath.Data.ByteString.Short.Hidden
193 changes: 193 additions & 0 deletions System/OsPath/Data/ByteString/Short/Hidden.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NoImplicitPrelude #-}
-- |
-- Module : System.OsPath.Data.ByteString.Short.Hidden
-- Copyright : (c) Duncan Coutts 2012-2013, Julian Ospald 2022
-- License : BSD-style
--
-- Maintainer : [email protected]
-- Stability : stable
-- Portability : ghc only
--
-- A compact representation suitable for storing short byte strings in memory.
--
-- In typical use cases it can be imported alongside "Data.ByteString", e.g.
--
-- > import qualified Data.ByteString as B
-- > import qualified Data.ByteString.Short as B
-- > (ShortByteString, toShort, fromShort)
--
-- Other 'ShortByteString' operations clash with "Data.ByteString" or "Prelude"
-- functions however, so they should be imported @qualified@ with a different
-- alias e.g.
--
-- > import qualified Data.ByteString.Short as B.Short
--
module System.OsPath.Data.ByteString.Short.Hidden

(

-- * The @ShortByteString@ type

ShortByteString(..),

-- ** Memory overhead
-- | With GHC, the memory overheads are as follows, expressed in words and
-- in bytes (words are 4 and 8 bytes on 32 or 64bit machines respectively).
--
-- * 'B.ByteString' unshared: 8 words; 32 or 64 bytes.
--
-- * 'B.ByteString' shared substring: 4 words; 16 or 32 bytes.
--
-- * 'ShortByteString': 4 words; 16 or 32 bytes.
--
-- For the string data itself, both 'ShortByteString' and 'B.ByteString' use
-- one byte per element, rounded up to the nearest word. For example,
-- including the overheads, a length 10 'ShortByteString' would take
-- @16 + 12 = 28@ bytes on a 32bit platform and @32 + 16 = 48@ bytes on a
-- 64bit platform.
--
-- These overheads can all be reduced by 1 word (4 or 8 bytes) when the
-- 'ShortByteString' or 'B.ByteString' is unpacked into another constructor.
--
-- For example:
--
-- > data ThingId = ThingId {-# UNPACK #-} !Int
-- > {-# UNPACK #-} !ShortByteString
--
-- This will take @1 + 1 + 3@ words (the @ThingId@ constructor +
-- unpacked @Int@ + unpacked @ShortByteString@), plus the words for the
-- string data.

-- ** Heap fragmentation
-- | With GHC, the 'B.ByteString' representation uses /pinned/ memory,
-- meaning it cannot be moved by the GC. This is usually the right thing to
-- do for larger strings, but for small strings using pinned memory can
-- lead to heap fragmentation which wastes space. The 'ShortByteString'
-- type (and the @Text@ type from the @text@ package) use /unpinned/ memory
-- so they do not contribute to heap fragmentation. In addition, with GHC,
-- small unpinned strings are allocated in the same way as normal heap
-- allocations, rather than in a separate pinned area.

-- * Introducing and eliminating 'ShortByteString's
empty,
singleton,
pack,
unpack,
fromShort,
toShort,

-- * Basic interface
snoc,
cons,
append,
last,
tail,
uncons,
uncons2,
head,
init,
unsnoc,
null,
length,

-- * Transforming ShortByteStrings
map,
reverse,
intercalate,

-- * Reducing 'ShortByteString's (folds)
foldl,
foldl',
foldl1,
foldl1',

foldr,
foldr',
foldr1,
foldr1',

-- ** Special folds
all,
any,
concat,

-- ** Generating and unfolding ByteStrings
replicate,
unfoldr,
unfoldrN,

-- * Substrings

-- ** Breaking strings
take,
takeEnd,
takeWhileEnd,
takeWhile,
drop,
dropEnd,
dropWhile,
dropWhileEnd,
breakEnd,
break,
span,
spanEnd,
splitAt,
split,
splitWith,
stripSuffix,
stripPrefix,

-- * Predicates
isInfixOf,
isPrefixOf,
isSuffixOf,

-- ** Search for arbitrary substrings
breakSubstring,

-- * Searching ShortByteStrings

-- ** Searching by equality
elem,

-- ** Searching with a predicate
find,
filter,
partition,

-- * Indexing ShortByteStrings
index,
indexMaybe,
(!?),
elemIndex,
elemIndices,
count,
findIndex,
findIndices,

-- * Low level conversions
-- ** Packing 'Foreign.C.String.CString's and pointers
packCString,
packCStringLen,

-- ** Using ShortByteStrings as 'Foreign.C.String.CString's
useAsCString,
useAsCStringLen,
) where

import Data.ByteString.Short.Internal
import System.OsPath.Data.ByteString.Short.Internal.Hidden

import Prelude (Maybe(..), Ord(..), Num(..), ($), otherwise)
import Data.Word (Word8)

uncons2 :: ShortByteString -> Maybe (Word8, Word8, ShortByteString)
uncons2 = \sbs ->
let l = length sbs
nl = l - 2
in if | l <= 1 -> Nothing
| otherwise -> let h = indexWord8Array (asBA sbs) 0
h' = indexWord8Array (asBA sbs) 1
t = create nl $ \mba -> copyByteArray (asBA sbs) 1 mba 0 nl
in Just (h, h', t)
Loading