Jebbs / DSFML

DSFML is a D binding of SFML

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Have Text use dchar buffer instead of dstring

Jebbs opened this issue · comments

I think it would be a better idea to use a string type instead of a dstring type in the Text class. This will use less memory on average, and the same amount of memory in the worst case.

I seriously doubt anyone uses explicit dstrings, and this would allow us to avoid the conversion.

To iterate through each codepoint (which is what SFML expects for glyphs and kerning), we can iterate through the string using byUTF!dchar(), which doesn't allocate extra memory as it lazily evaluates the codepoints.

It might be better to use a character buffer instead to prevent unnecessary allocations. The buffer would only increase in size if more space was needed, but would otherwise use the same memory when the text changed.

The actual solution I chose ended up being a dchar buffer. I decided to keep using dchars to keep the code essentially synchronized with SFML's, but I liked the idea of using a buffer to keep the number of allocations at a minimum when the contents change regularly.

Title of the issue is updated to reflect that.

Closed by #286