[Issue 18084] [REG2.072] tempCString buffer size is unittest-versioned

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Dec 16 12:45:57 UTC 2017


https://issues.dlang.org/show_bug.cgi?id=18084

--- Comment #4 from anonymous4 <dfj1esp02 at sneakemail.com> ---
A variant of code:
---
//field size doesn't depend on unittest version (to avoid corruption)
//use `_buff` property to access the buffer
To[256 / To.sizeof] _buffer; // the 'small string optimization'

To[] _buff()
{
        version (unittest)
        {
                // smaller size to trigger reallocations
                return _buffer[0..16/To.sizeof];
        }
        else
        {
                return _buffer; // production size
        }
}
---
Also reallocation logic is quite smart.

--


More information about the Digitalmars-d-bugs mailing list