Better way to append to array than ~= ?
Vladimirs Nordholm
v at vladde.net
Wed Apr 4 15:51:20 UTC 2018
On Tuesday, 3 April 2018 at 20:41:01 UTC, Alex wrote:
> On Tuesday, 3 April 2018 at 20:02:46 UTC, Vladimirs Nordholm
> wrote:
>> On Tuesday, 3 April 2018 at 19:53:11 UTC, Meta wrote:
>>> [...]
>>
>> I don't think I know the size of the arguments.
>>
>> If I pass in "123" and MySpecialType('a'), the result should
>> be:
>>
>> assert(foo("123", MySpecialType('a')) ==
>> [MySpecialType('1'), MySpecialType('2'), MySpecialType('3'),
>> MySpecialType('a')]);
>>
>> What should the length of the pre-allocated array be?
>
> In my try, I iterate the args twice. The first time to
> calculate the number of elements, then preallocate and then
> iterate them again and constructing the proper objects.
>
> It is not nice, but about 1/3 of time, compared to original
> version, compiled in release mode.
>
> https://run.dlang.io/is/E6ckog
Yeah, I will probably need to iterate twice.
Thanks a bunch 👍
More information about the Digitalmars-d-learn
mailing list