www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Should we add another SmallArray to DMD?

reply Guillaume Chatelet <chatelet.guillaume gmail.com> writes:
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.
Jul 05 2016
parent reply Guillaume Chatelet <chatelet.guillaume gmail.com> writes:
On Tuesday, 5 July 2016 at 19:41:18 UTC, Guillaume Chatelet wrote:
 DMD currently provides the Array type:
 https://github.com/dlang/dmd/blob/master/src/root/array.d

 [...]
Walter, Daniel, Thoughts?
Jul 06 2016
parent reply Stefan Koch <uplink.coder googlemail.com> writes:
On Thursday, 7 July 2016 at 06:39:19 UTC, Guillaume Chatelet 
wrote:
 On Tuesday, 5 July 2016 at 19:41:18 UTC, Guillaume Chatelet 
 wrote:
 DMD currently provides the Array type:
 https://github.com/dlang/dmd/blob/master/src/root/array.d

 [...]
Walter, Daniel, Thoughts?
I guess a few number of the perf difference this can make would be helpful.
Jul 07 2016
parent reply Guillaume Chatelet <chatelet.guillaume gmail.com> writes:
On Thursday, 7 July 2016 at 07:56:44 UTC, Stefan Koch wrote:
 On Thursday, 7 July 2016 at 06:39:19 UTC, Guillaume Chatelet 
 wrote:
 On Tuesday, 5 July 2016 at 19:41:18 UTC, Guillaume Chatelet 
 wrote:
 DMD currently provides the Array type:
 https://github.com/dlang/dmd/blob/master/src/root/array.d

 [...]
Walter, Daniel, Thoughts?
I guess a few number of the perf difference this can make would be helpful.
It's not so much about performance gain (although it wouldn't hurt). It's more about codebase sanity: idiomatic D, documentation, tests. I think it's currently hard to contribute to DMD. Sure it improved a lot with the migration to D but it still bears the marks of the past.
Jul 07 2016
parent Charles Hixson via Digitalmars-d <digitalmars-d puremagic.com> writes:
On 07/07/2016 03:51 AM, Guillaume Chatelet via Digitalmars-d wrote:
 On Thursday, 7 July 2016 at 07:56:44 UTC, Stefan Koch wrote:
 On Thursday, 7 July 2016 at 06:39:19 UTC, Guillaume Chatelet wrote:
 On Tuesday, 5 July 2016 at 19:41:18 UTC, Guillaume Chatelet wrote:
 DMD currently provides the Array type:
 https://github.com/dlang/dmd/blob/master/src/root/array.d

 [...]
Walter, Daniel, Thoughts?
I guess a few number of the perf difference this can make would be helpful.
It's not so much about performance gain (although it wouldn't hurt). It's more about codebase sanity: idiomatic D, documentation, tests. I think it's currently hard to contribute to DMD. Sure it improved a lot with the migration to D but it still bears the marks of the past.
If it's just for code sanity, why wouldn't an alias suffice? I often alias types to create a "type" for a specialized purpose. Of course, if you want a real type you could wrap it in a struct...which I do with classes when it's *IMPORTANT* that the finalizer be called.
Jul 07 2016