Bug 11335 – Appender.reserve is overzealous and wrong
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-23T18:32:00Z
Last change time
2013-10-23T18:33:42Z
Keywords
pull
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2013-10-23T18:32:04Z
Comment #1 by andrej.mitrovich — 2013-10-23T18:33:04Z
Quote from pull:
== 1 ==
Appender.reserve is overzealous. Given a request of a capacity of size, it basically took the request, made that grow, and then reserved that. This results in things like:
auto app = Appender!(int[]);
app.reserve(65_000);
writeln(app.capacity); //Prints abous 107_000 on my machine. Pointless.
== 2 ==
There was a little bug in reserve, where it called ensureAddable(requestedSize - currentCapacity) as opposed to ensureAddable(requestedSize - currentSize). This for example, things like this failed:
A case that failed:
Appender with 32_000 element, and 64_000 capacity.
Request 80_000 capacity
=> ensureAddable(48_000)
=> do nothing
=> resulting capacity is actually smaller than 80_000
Comment #2 by andrej.mitrovich — 2013-10-23T18:33:12Z