Optimize SourceOfRandomness#choose(java.util.Collection<T>)
vlsi opened this issue · 4 comments
vlsi commented
Currently SourceOfRandomness#choose(java.util.Collection) converts the collection to array, however
- If collection size is 1, then there's no need to generate a random number
- If collection is a
List
+java.util.RandomAccess
, then.get(index)
would be faster than collecting the values to array.
choose(T[] items)
could be optimized as well for the case of single item (avoid generating random when outcome is known to be 0)
pholser commented
@visi Sounds reasonable. Would you be willing to make this change and submit a PR?
vlsi commented
I do not get it. Do you suggest me to create two PRs?