[
https://issues.apache.org/jira/browse/COLLECTIONS-773?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17239322#comment-17239322
]
Gary D. Gregory commented on COLLECTIONS-773:
---------------------------------------------
Hi [~monperrus],
It still works because of the way that map (and most maps) is internally
structured: it's an array of linked lists.
If you comment out the body of ensureCapacity, then the shape of the internal
structure is "wrong" in the sense that it becomes inefficient. The array never
grows, so each linked lists grows instead to accommodate new values.
As the map grows, the insertion of new elements will slow down as will the key
lookup.
You could write tests that insure that ensureCapacity() works as documented by
checking the state of the map internals after CRUD operations.
> method AbstractHashedMap#ensureCapacity is not well tested
> ----------------------------------------------------------
>
> Key: COLLECTIONS-773
> URL: https://issues.apache.org/jira/browse/COLLECTIONS-773
> Project: Commons Collections
> Issue Type: Test
> Components: Map
> Affects Versions: Nightly Builds, 4.3, 4.4
> Reporter: Martin Monperrus
> Priority: Minor
> Labels: performance, test
>
> Hi Apache 🏹!
> I notice that method AbstractHashedMap#ensureCapacity seems quite important,
> it is executed 11885 times by the test suite.
> Yet, when I completely remove the body of the method, leaving the method
> doing nothing, no test breaks.
> It that normal or should we add test or an assertion to specify its behavior?
> Thanks a lot for the great library!
> --Martin
--
This message was sent by Atlassian Jira
(v8.3.4#803005)