|
newtype ShortText = ST { unST :: BS.Short.ShortByteString } |
|
deriving (Eq,Ord,Generic,Data,Typeable) |
Most of Cabal textual data (PackageName, ModuleName, etc.) are newtypes over ShortText. This provides for compact storage, but almost any operation on them requires conversion to String and back. Indeed, working with Unicode in ShortByteString directly is painful.
Could we replace ShortByteString by Text in ShortText?
newtype ShortText = ST { unST :: Data.Text.Text }
This would simplify boilerplate in Distribution.Utils.ShortText and it would be trivial to expose more utilities to avoid ubiquitous conversions to String. Potentially we can also parse directly into Text (instead of parsing ByteString and converting later).
Note that Cabal already depends on text via parsec, so this move does not change dependency graph.
(Another option is to use text-short, but this one is slightly less conservative. If the proposal is implemented, it would be trivial to swap text and text-short, as they provide almost the same API)
CC @phadej
cabal/Cabal-syntax/src/Distribution/Utils/ShortText.hs
Lines 95 to 96 in 0a2e68c
Most of Cabal textual data (
PackageName,ModuleName, etc.) are newtypes overShortText. This provides for compact storage, but almost any operation on them requires conversion toStringand back. Indeed, working with Unicode inShortByteStringdirectly is painful.Could we replace
ShortByteStringbyTextinShortText?This would simplify boilerplate in
Distribution.Utils.ShortTextand it would be trivial to expose more utilities to avoid ubiquitous conversions toString. Potentially we can also parse directly intoText(instead of parsingByteStringand converting later).Note that
Cabalalready depends ontextviaparsec, so this move does not change dependency graph.(Another option is to use
text-short, but this one is slightly less conservative. If the proposal is implemented, it would be trivial to swaptextandtext-short, as they provide almost the same API)CC @phadej