-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: improve compareTo of LabelMultisetEntryList
refactor: Comparable<LabelMultisetEntryList> organization the `put` operation of `TreeMap` is expensive, since `compareTo` is expensive. So we want to reduce the number of calls to this. To that end we don't want to check equality BEFORE calling `put` since both will calculate `compareTo`. So we `putIfAbsent` on the list. However, the list at this point is a reference that can change, so we need to copy the data. But we don't want to always copy, since most lists (in most cases) are not unique, and we only need a single copy to reference in the `TreeMap`. So only copy the data `via addAll` when the list is a newly added one. In addition, move the `Comparable` implementation to a package-private subclass that also reuses a single ref from construction to do the comparison. smarter way of detecting when all entries are empty (`size()` was expensive, since it requires iterating over all entries)
- Loading branch information
Showing
3 changed files
with
28 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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