@@ -183,6 +183,9 @@ module Data.Text
184 -- -* Ordered text
184 -- -* Ordered text
185 -- , sort
185 -- , sort
187+ -- * Low level operations
188import Prelude (Char, Bool(..), Int, Maybe(..), String,
191import Prelude (Char, Bool(..), Int, Maybe(..), String,
@@ -1577,3 +1580,19 @@ emptyError fun = P.error $ "Data.Text." ++ fun ++ ": empty input"
1578overflowError :: String -> a
1581overflowError :: String -> a
1579overflowError fun = P.error $ "Data.Text." ++ fun ++ ": size overflow"
1582overflowError fun = P.error $ "Data.Text." ++ fun ++ ": size overflow"
1584+-- | /O(n)/ Make a distinct copy of the given string, sharing no
1585+-- storage with the original string.
1587+-- As an example, suppose you read a large string, of which you need
1588+-- only a small portion. If you do not use 'copy', the entire original
1589+-- array will be kept alive in memory by the smaller string. Making a
1590+-- copy \"breaks the link\" to the original array, allowing it to be
1591+-- garbage collected if there are no other live references to it.
1592+copy :: Text -> Text
1593+copy (Text arr off len) = Text (A.run go) 0 len
1597+ A.copyI marr 0 arr off len