X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Data%2FPackedString.hs;h=46fb4baf706a8c5d9cf2ab5a8d6f03b83cc855c2;hb=0a41af38169035a4359c0c29bc1219af564dce64;hp=cd4fad98f36ca29d8c861bdabf8d24b750b297ac;hpb=d539a9457e2c79a9f13744d073d3f253ea2fb33e;p=ghc-base.git diff --git a/Data/PackedString.hs b/Data/PackedString.hs index cd4fad9..46fb4ba 100644 --- a/Data/PackedString.hs +++ b/Data/PackedString.hs @@ -83,6 +83,11 @@ import System.IO -- efficient operations. A 'PackedString' contains full Unicode 'Char's. newtype PackedString = PS (UArray Int Char) +-- ToDo: we could support "slices", i.e. include offset and length fields into +-- the string, so that operations like take/drop could be O(1). Perhaps making +-- a slice should be conditional on the ratio of the slice/string size to +-- limit memory leaks. + instance Eq PackedString where (PS x) == (PS y) = x == y @@ -116,7 +121,7 @@ packString str = packNChars (length str) str -- | The 'packNChars' function creates a 'PackedString' out of the -- first @len@ elements of the given 'String'. packNChars :: Int -> [Char] -> PackedString -packNChars len str = PS (array (0,len-1) (zip [0..] str)) +packNChars len str = PS (listArray (0,len-1) str) -- ----------------------------------------------------------------------------- -- Destructor functions (taking PackedStrings apart) @@ -261,7 +266,7 @@ joinPS filler pss = concatPS (splice pss) * joinPS (packString [x]) (splitPS x ls) = ls -} --- | The 'splitPS' function splits the input string on each occurance of the given 'Char'. +-- | The 'splitPS' function splits the input string on each occurrence of the given 'Char'. splitPS :: Char -> PackedString -> [PackedString] splitPS c = splitWithPS (== c) @@ -309,7 +314,7 @@ substrPS (PS ps) begin end = packString [ ps ! i | i <- [begin..end] ] -- | Outputs a 'PackedString' to the specified 'Handle'. -- -- NOTE: the representation of the 'PackedString' in the file is assumed to --- be in the ISO-8859-1 encoding. In other words, only the least signficant +-- be in the ISO-8859-1 encoding. In other words, only the least significant -- byte is taken from each character in the 'PackedString'. hPutPS :: Handle -> PackedString -> IO () hPutPS h (PS ps) = do @@ -332,7 +337,7 @@ hGetPS h i = do arr <- newArray_ (0, i-1) l <- hGetArray h arr i chars <- mapM (\i -> readArray arr i >>= return.chr.fromIntegral) [0..l-1] - return (packString chars) + return (packNChars l chars) #else /* __NHC__ */