DMD currently provides the Array type:
https://github.com/dlang/dmd/blob/master/src/root/array.d

It is primarily designed to interact with C++.
It provides the small array optimization which is good, but its stack space is one element and cannot be changed, making it not suitable for small string buffers.

As a matter of fact we also have OutBuffer which reimplements the allocation strategy a second time (with no small string optimization)
https://github.com/dlang/dmd/blob/master/src/root/outbuffer.d

It is also quite old, not tested (at least I didn't find them), and does not follow D idioms.

Also note that because Array is "extern (C++)", it's not possible to add SMALLARRAYCAP as a template parameter (bug in the C++ name mangler).

Proposal:
---------
As for LLVM, create a few tested D idiomatic facilities to use in the front end: SmallVector, SmallString to begin with.

Here is a first take at SmallVector (no doc yet)
https://gist.github.com/gchatelet/876adfb59abe1dda58ba24d63d4e418d

I'm half convinced for now so I would like some feedback before investing more time.

Reply via email to