-
-
Notifications
You must be signed in to change notification settings - Fork 741
Appender.reserve: Overzealous and wrong #1410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Pinging for review. |
LGTM P.S. One unrelated thing is that the algorithm for grow factor is not described at all leaving me wondering how did these equations poped up in the first place (sometime back in 2010 by Steve). |
I'm not sure what the origin of the algorithm is, but it makes sense to me. Using In any case, I didn't want to rewrite it. I also moved it outside of Rebased and ready for review. |
pining @blackwhale && @schveiguy . |
I'd gladly merge but I'm not a commiter... And Steven seems to be quite busy elsewhere. |
pinging @schveiguy , @AndrejMitrovic and @9rnsr . |
LGTM. |
Appender.reserve: Overzealous and wrong
Thanks! (but please make bugzilla reports for these pulls in the future) |
I know this is really really old, but somehow I happened to notice it in my email I was about to delete. The newCapacity function was cut and paste from the runtime's append growth function. I did NOT write it, but I did fix it a long time ago. Somewhere in the history of d runtime mailing list, you can find what I had said. There were some bizarre relationships between size of the element and the growth function. In any case, I agree if you are simply reserving, the appender does not need to use new capacity at all. It should only be in the case of appending. In the case of reserve, it should just reserve exactly that much, plus whatever is required to make a complete block. I think that's the way arr.reserve works also. So good change, thanks! |
This contains two simple fixes:
== 1 ==
Appender.reserve
is overzealous. Given a request of a capacity ofsize
, it basically took the request, made that grow, and then reserved that. This results in things like:The fix is for to make
ensureAddable
'snewCapacity
to be based on the old capacity. Then, the final capacity is simply the max between the re-evaluated old=>new capacity, and the requested capacity.== 2 ==
There was a little bug in reserve, where it called
ensureAddable(requestedSize - currentCapacity)
as opposed toensureAddable(requestedSize - currentSize)
. This for example, things like this failed:A case that failed:
http://d.puremagic.com/issues/show_bug.cgi?id=11335