Skip to content

Use Text instead of ShortByteString in ShortText? #8256

@Bodigrim

Description

@Bodigrim

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions