From a009d8c981cbb0948a93c4a01ce0d24bacf8ae1a Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 13 Oct 2022 09:32:24 +0200 Subject: [PATCH] language: remove compatibility with go < 1.2 This was added in 9f86e0be982f3e937cd7146d47f65a80d618e8bc to provide compatibility with go1.1, which is an obsolete version. Signed-off-by: Sebastiaan van Stijn --- language/go1_1.go | 39 --------------------------------------- language/go1_2.go | 12 ------------ language/parse.go | 3 ++- 3 files changed, 2 insertions(+), 52 deletions(-) delete mode 100644 language/go1_1.go delete mode 100644 language/go1_2.go diff --git a/language/go1_1.go b/language/go1_1.go deleted file mode 100644 index c7435583..00000000 --- a/language/go1_1.go +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build !go1.2 -// +build !go1.2 - -package language - -import "sort" - -func sortStable(s sort.Interface) { - ss := stableSort{ - s: s, - pos: make([]int, s.Len()), - } - for i := range ss.pos { - ss.pos[i] = i - } - sort.Sort(&ss) -} - -type stableSort struct { - s sort.Interface - pos []int -} - -func (s *stableSort) Len() int { - return len(s.pos) -} - -func (s *stableSort) Less(i, j int) bool { - return s.s.Less(i, j) || !s.s.Less(j, i) && s.pos[i] < s.pos[j] -} - -func (s *stableSort) Swap(i, j int) { - s.s.Swap(i, j) - s.pos[i], s.pos[j] = s.pos[j], s.pos[i] -} diff --git a/language/go1_2.go b/language/go1_2.go deleted file mode 100644 index 77aaaa29..00000000 --- a/language/go1_2.go +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build go1.2 -// +build go1.2 - -package language - -import "sort" - -var sortStable = sort.Stable diff --git a/language/parse.go b/language/parse.go index b982d9e4..4d57222e 100644 --- a/language/parse.go +++ b/language/parse.go @@ -6,6 +6,7 @@ package language import ( "errors" + "sort" "strconv" "strings" @@ -206,7 +207,7 @@ func ParseAcceptLanguage(s string) (tag []Tag, q []float32, err error) { tag = append(tag, t) q = append(q, float32(w)) } - sortStable(&tagSort{tag, q}) + sort.Stable(&tagSort{tag, q}) return tag, q, nil }