currently does this
which involves scraping over an array. This is rather slow for a big container and is proving to be a bottleneck in our application.
If you have n containers being instantiated then you'll do contains n times on a list o which will be o(n^2) calls to equals.
Two simple fixes spring to mind:
- Keep the component adapters in a set instead - if you use a linked hash set then you'd get exactly the same iteration order but contains() will be fast.
- Use the keyToAdapterCache map instead like so:
getComponentKeyToAdapterCache().get(componentAdapter.getComponentKey()) == componentAdapter
A more involved alternative might be to admit that a given ComponentAdapter needs to know its parent PicoContainer and hence keep a back-reference so you could do componentAdapater.getPicoContainer() == this.