Skip to content

Commit

Permalink
Use HashSet in TestAjaxRequestHandler - trading speed for maintaining…
Browse files Browse the repository at this point in the history
… insertion order
  • Loading branch information
ursjoss committed Jul 4, 2020
1 parent d2f12b1 commit 2258b71
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ import java.util.HashSet
* with some minor refactorings but with one major change that has a significant effect
* on the duration required to test core-web:
*
* Instead of using a `LinkedList` to store the listeners, we use a [LinkedHashSet]. This
* Instead of using a `LinkedList` to store the listeners, we use a [HashSet]. This
* improves the time complexity of the [contains] method on the collection in the
* method [addListener] from O(n) to constant time O(1) while still keeping the order.
* method [addListener] from O(n) to constant time O(1). It does not maintain
* insertion order though. If insertion order would be important, we could use
* LinkedHashSet, which is slower than HashSet however.
*
* When running the tests with mockk, this decreased the total time used for `gradlew check`
* from several hours to 20 minutes.
Expand Down Expand Up @@ -98,7 +100,7 @@ class TestAjaxRequestHandler(page: Page) : AjaxRequestTarget {
Args.notNull(listener, "listener")
assertListenersNotFrozen()
if (listeners == null)
listeners = LinkedHashSet()
listeners = HashSet()
if (listener !in listeners!!)
listeners!!.add(listener)
}
Expand Down

0 comments on commit 2258b71

Please sign in to comment.