@@ -85,7 +85,7 @@ module Data.ByteString.Short.Internal (
8585 any ,
8686 concat ,
8787
88- -- ** Generating and unfolding ByteStrings
88+ -- ** Generating and unfolding ShortByteStrings
8989 replicate ,
9090 unfoldr ,
9191 unfoldrN ,
@@ -280,12 +280,6 @@ import qualified Language.Haskell.TH.Syntax as TH
280280-- 'ByteString' (at the cost of copying the string data). It supports very few
281281-- other operations.
282282--
283- -- It is suitable for use as an internal representation for code that needs
284- -- to keep many short strings in memory, but it /should not/ be used as an
285- -- interchange type. That is, it should not generally be used in public APIs.
286- -- The 'ByteString' type is usually more suitable for use in interfaces; it is
287- -- more flexible and it supports a wide range of operations.
288- --
289283data ShortByteString = SBS ByteArray #
290284 deriving Typeable
291285
@@ -373,6 +367,8 @@ null :: ShortByteString -> Bool
373367null sbs = length sbs == 0
374368
375369-- | /O(1)/ 'ShortByteString' index (subscript) operator, starting from 0.
370+ --
371+ -- This is a partial function, consider using 'indexMaybe' instead.
376372index :: HasCallStack => ShortByteString -> Int -> Word8
377373index sbs i
378374 | i >= 0 && i < length sbs = unsafeIndex sbs i
@@ -734,7 +730,7 @@ tail = \sbs ->
734730 True -> errorEmptySBS " tail"
735731 False -> create nl $ \ mba -> copyByteArray (asBA sbs) 1 mba 0 nl
736732
737- -- | /O(n)/ Extract the head and tail of a ByteString , returning Nothing
733+ -- | /O(n)/ Extract the ' head' and ' tail' of a ShortByteString , returning ' Nothing'
738734-- if it is empty.
739735--
740736-- @since 0.11.3.0
@@ -774,7 +770,7 @@ init = \sbs ->
774770 True -> errorEmptySBS " init"
775771 False -> create nl $ \ mba -> copyByteArray (asBA sbs) 0 mba 0 nl
776772
777- -- | /O(n)/ Extract the 'init' and 'last' of a ByteString , returning Nothing
773+ -- | /O(n)/ Extract the 'init' and 'last' of a ShortByteString , returning ' Nothing'
778774-- if it is empty.
779775--
780776-- @since 0.11.3.0
@@ -892,7 +888,7 @@ intercalate sep = \case
892888
893889
894890-- ---------------------------------------------------------------------
895- -- Reducing 'ByteString 's
891+ -- Reducing 'ShortByteString 's
896892
897893-- | 'foldl', applied to a binary operator, a starting value (typically
898894-- the left-identity of the operator), and a ShortByteString, reduces the
@@ -971,8 +967,8 @@ all k = \sbs ->
971967 in go 0
972968
973969
974- -- | /O(n)/ Applied to a predicate and a ByteString , 'any' determines if
975- -- any element of the 'ByteString ' satisfies the predicate.
970+ -- | /O(n)/ Applied to a predicate and a 'ShortByteString' , 'any' determines if
971+ -- any element of the 'ShortByteString ' satisfies the predicate.
976972--
977973-- @since 0.11.3.0
978974any :: (Word8 -> Bool ) -> ShortByteString -> Bool
@@ -1235,7 +1231,7 @@ stripPrefix sbs1 = \sbs2 -> do
12351231-- Unfolds and replicates
12361232
12371233
1238- -- | /O(n)/ 'replicate' @n x@ is a ByteString of length @n@ with @x@
1234+ -- | /O(n)/ 'replicate' @n x@ is a ShortByteString of length @n@ with @x@
12391235-- the value of every element. The following holds:
12401236--
12411237-- > replicate w c = unfoldr w (\u -> Just (u,u)) c
@@ -1430,8 +1426,8 @@ breakSubstring pat =
14301426elem :: Word8 -> ShortByteString -> Bool
14311427elem c = \ sbs -> case elemIndex c sbs of Nothing -> False ; _ -> True
14321428
1433- -- | /O(n)/ 'filter', applied to a predicate and a ByteString ,
1434- -- returns a ByteString containing those characters that satisfy the
1429+ -- | /O(n)/ 'filter', applied to a predicate and a ShortByteString ,
1430+ -- returns a ShortByteString containing those characters that satisfy the
14351431-- predicate.
14361432--
14371433-- @since 0.11.3.0
@@ -1460,7 +1456,7 @@ filter k = \sbs -> let l = length sbs
14601456 else
14611457 go' (br+ 1 ) bw
14621458
1463- -- | /O(n)/ The 'find' function takes a predicate and a ByteString ,
1459+ -- | /O(n)/ The 'find' function takes a predicate and a ShortByteString ,
14641460-- and returns the first element in matching the predicate, or 'Nothing'
14651461-- if there is no such element.
14661462--
@@ -1472,8 +1468,8 @@ find f = \sbs -> case findIndex f sbs of
14721468 Just n -> Just (sbs `index` n)
14731469 _ -> Nothing
14741470
1475- -- | /O(n)/ The 'partition' function takes a predicate a ByteString and returns
1476- -- the pair of ByteStrings with elements which do and do not satisfy the
1471+ -- | /O(n)/ The 'partition' function takes a predicate a ShortByteString and returns
1472+ -- the pair of ShortByteStrings with elements which do and do not satisfy the
14771473-- predicate, respectively; i.e.,
14781474--
14791475-- > partition p bs == (filter p sbs, filter (not . p) sbs)
@@ -1539,7 +1535,7 @@ count w = \sbs@(SBS ba#) -> accursedUnutterablePerformIO $
15391535 fromIntegral <$> c_count ba# (fromIntegral $ length sbs) w
15401536
15411537-- | /O(n)/ The 'findIndex' function takes a predicate and a 'ShortByteString' and
1542- -- returns the index of the first element in the ByteString
1538+ -- returns the index of the first element in the ShortByteString
15431539-- satisfying the predicate.
15441540--
15451541-- @since 0.11.3.0
0 commit comments