Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8333133

Simplify QuickSort::sort

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 24
    • None
    • hotspot
    • b04

      QuickSort::sort has an argument called "idempotent" whose usage is complicated and questionable. It doesn't make the sort stable or anything like that. Instead, it eliminates swapping of pairs of equivalent values, but at a cost.

      It's only potentially beneficial if

      (1) There is at least one subset of elements that are all equivalent.
      (2) The element type is expensive to swap.

      There are currently 3 uses of this feature, none of which satisfy either of those requirements. And none of the sort calls that don't request this feature would benefit either. Most of our sorts are of sequences of unique values. And needing to swap a sequence that contains many equivalent values that are expensive to swap just doesn't seem at all likely.

      This feature also adds some complexity to the implementation.

      We should fix the current non-beneficial uses, and then remove this then unused feature.

      Aside: As currently implemented, there is a cost of an extra call to the comparison function in order to potentially eliminate the swap, in order to determine whether the values to be swapped are equivalent. However, that extra call could be removed (reducing the cost of the feature) by using the results from the comparisons with the pivots.

            kbarrett Kim Barrett
            kbarrett Kim Barrett
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: