Skip to content

sort: forward fixed-type slice sorting to slices package #61180

@eliben

Description

@eliben

The sorting functions in the slices package are generally faster than their equivalents in the sort package. We've added doc comments to the sort package in 1.21 pointing at the faster equivalents, but for now did not modify their implementation. Issues like #60777 show that there could be some rare scenarios where a change would introduce a regression.

In 1.22 we should consider forwarding the implementation of functions like sort.Ints to slices.Sort:

func Ints(x []int) {
  slices.Sort(x)
}

The following functions can be forwarded:

  • sort.Ints
  • sort.Strings
  • sort.Float64s (but we'll need to double check that the FP semantics align, e.g. NaN)
  • sort.IntsAreSorted
  • sort.StringsAreSorted
  • sort.Float64sAreSorted

The other functions in the sort package have slightly different semantics, so it may just be sufficient to retain comments suggesting to consider the slices package instead.

Metadata

Metadata

Assignees

Labels

NeedsFixThe path to resolution is known, but the work has not been done.Performance

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions