Bug 2528 – Arrays in Phobos shold be pre-allocated.

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-12-20T20:27:00Z
Last change time
2015-06-09T01:20:50Z
Assigned to
andrei
Creator
dsimcha

Comments

Comment #0 by dsimcha — 2008-12-20T20:27:59Z
Looking at the sources to Phobos, I see several places, including std.algorithm.map(), and the array-to-array conversion function of std.conv, where the ~= operator is used, even though the length of the array returned by these functions is known at the beginning of the function. This severely hurts the performance of these functions, given how slow ~= is. Furthermore, even if ~= were efficient, reallocating an array instead of preallocating is still too inefficient when it can be trivially optimized out.
Comment #1 by andrei — 2008-12-20T21:37:38Z
Good point, will fix.
Comment #2 by dsimcha — 2009-04-24T13:53:54Z
This looks to have been resolved in the new Phobos.