Replace large switch statement with a lookup table.#212
Open
Replace large switch statement with a lookup table.#212
Conversation
|
|
||
| // A statically initialized Map of IRIs to HQDM classes. | ||
| private static final Map<IRI, java.lang.Class<? extends Thing>> iriToClassMap = new HashMap<>(250); | ||
| private static final Map<IRI, java.lang.Class<? extends Thing>> iriToClassMap = new HashMap<>(400); |
Contributor
There was a problem hiding this comment.
Why was this increased to 400? Was it to create headroom in case additional records are to be added? If so, this still seems to be an arbitrary number.
Collaborator
Author
There was a problem hiding this comment.
It's the starting capacity of the HashMap to prevent costly reorganisation of the data structure during its initial population. 250 was fine until we added the ability to extend HQDM, because extension modules can add to this map, and yes 400 is an arbitrary number which it probably has to be since we won't know if any extensions will be added or how many, so eventually the HashMap will have to reorganise itself anyway when there are many extension classes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #211
For discussion, but this looks better to me than the original
switchstatement. Feel free not to merge if you disagree :-)Hopefully it will also be more efficient since it removes a large cascading
if...else...construct (depending on compiler optimisations of course).