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:
On Tuesday, 3 April 2018 at 19:02:25 UTC, Vladimirs Nordholm wrote:
[...]

In this specific case, since you know the length of `Args`, you can pre-allocate an array of that size and loop through it doing your initialization.

However, if you want really performant code, you should allocate a static array on the stack outside of the function and pass it in as a buffer.

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?

You know the static types of the arguments, so it is not impossible. However, the more flexible you need to be, the more complex your code will have to be, and it probably won't be worth the added complexity. Anyway, sorry for derailing a bit. That's not really your question.

Using Appender!MySpecialType might be marginally faster than ~=, but from the looks of it you are already using Appender. I don't know if there's much more you can do to speed up appending without just rolling your own solution or restructuring your code.

Reply via email to