This patch implements a shortcut in sort!(::OrderedDict) to return
early in case the dict is already sorted. This avoids allocation of the
permutation vector and new arrays for keys and vals. This
optimization exist already in Base for sorting arrays, and checking for
sortedness is cheap in comparison to do the sorting.
Note that sort!(x::OrderedSet) already has this optimization
implicitly since it uses Base's sort! implementation on
(x.dict.keys)::Vector.
This patch implements a shortcut in
sort!(::OrderedDict)
to return early in case the dict is already sorted. This avoids allocation of the permutation vector and new arrays forkeys
andvals
. This optimization exist already in Base for sorting arrays, and checking for sortedness is cheap in comparison to do the sorting.Note that
sort!(x::OrderedSet)
already has this optimization implicitly since it uses Base'ssort!
implementation on(x.dict.keys)::Vector
.