New Upstream Release - golang-github-shenwei356-natsort
Ready changes
Summary
Merged new upstream version: 0.0~git20220117.580176a (was: 0.0~git20190418.600d539).
Resulting package
Built on 2023-01-17T19:33 (took 9m49s)
The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:
apt install -t fresh-releases golang-github-shenwei356-natsort-dev
Lintian Result
- golang-github-shenwei356-natsort-dev_0.0~git20220117.580176a-1~jan+nur2_all.deb
- golang-github-shenwei356-natsort_0.0~git20220117.580176a-1~jan+nur2.dsc
- golang-github-shenwei356-natsort_0.0~git20220117.580176a-1~jan+nur2_amd64.buildinfo
- golang-github-shenwei356-natsort_0.0~git20220117.580176a-1~jan+nur2_amd64.changes
Diff
diff --git a/debian/changelog b/debian/changelog
index 7d445c6..cb9230f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+golang-github-shenwei356-natsort (0.0~git20220117.580176a-1) UNRELEASED; urgency=low
+
+ * New upstream snapshot.
+
+ -- Debian Janitor <janitor@jelmer.uk> Tue, 17 Jan 2023 19:24:02 -0000
+
golang-github-shenwei356-natsort (0.0~git20190418.600d539-3) unstable; urgency=medium
[ Debian Janitor ]
diff --git a/natsort.go b/natsort.go
index 4cb341f..70a8bce 100644
--- a/natsort.go
+++ b/natsort.go
@@ -25,10 +25,10 @@ func (s stringSlice) Swap(a, b int) {
s[a], s[b] = s[b], s[a]
}
-func chunkify(s string) []string {
- re, _ := regexp.Compile(`(\d+|\D+)`)
+var chunkifyRegexp = regexp.MustCompile(`(\d+|\D+)`)
- return re.FindAllString(s, -1)
+func chunkify(s string) []string {
+ return chunkifyRegexp.FindAllString(s, -1)
}
// Sort sorts a list of strings in a natural order
@@ -54,6 +54,10 @@ func Compare(a, b string, ignoreCase bool) bool {
nChunksB := len(chunksB)
for i := range chunksA {
+ if i >= nChunksB {
+ return false
+ }
+
aInt, aErr := strconv.Atoi(chunksA[i])
bInt, bErr := strconv.Atoi(chunksB[i])
diff --git a/natsort_test.go b/natsort_test.go
index 7a683d2..b3d0e85 100644
--- a/natsort_test.go
+++ b/natsort_test.go
@@ -6,46 +6,46 @@ import (
"testing"
)
-func Test_Sort1(t *testing.T) {
- testList := []string{
- "1000X Radonius Maximus",
- "10X Radonius",
- "200X Radonius",
- "20X Radonius",
- "20X Radonius Prime",
- "30X Radonius",
- "40X Radonius",
- "Allegia 50 Clasteron",
- "Allegia 500 Clasteron",
- "Allegia 50B Clasteron",
- "Allegia 51 Clasteron",
- "Allegia 6R Clasteron",
- "Alpha 100",
- "Alpha 2",
- "Alpha 200",
- "Alpha 2A",
- "Alpha 2A-8000",
- "Alpha 2A-900",
- "Callisto Morphamax",
- "Callisto Morphamax 500",
- "Callisto Morphamax 5000",
- "Callisto Morphamax 600",
- "Callisto Morphamax 6000 SE",
- "Callisto Morphamax 6000 SE2",
- "Callisto Morphamax 700",
- "Callisto Morphamax 7000",
- "Xiph Xlater 10000",
- "Xiph Xlater 2000",
- "Xiph Xlater 300",
- "Xiph Xlater 40",
- "Xiph Xlater 5",
- "Xiph Xlater 50",
- "Xiph Xlater 500",
- "Xiph Xlater 5000",
- "Xiph Xlater 58",
- "",
- }
+var testList = []string{
+ "1000X Radonius Maximus",
+ "10X Radonius",
+ "200X Radonius",
+ "20X Radonius",
+ "20X Radonius Prime",
+ "30X Radonius",
+ "40X Radonius",
+ "Allegia 50 Clasteron",
+ "Allegia 500 Clasteron",
+ "Allegia 50B Clasteron",
+ "Allegia 51 Clasteron",
+ "Allegia 6R Clasteron",
+ "Alpha 100",
+ "Alpha 2",
+ "Alpha 200",
+ "Alpha 2A",
+ "Alpha 2A-8000",
+ "Alpha 2A-900",
+ "Callisto Morphamax",
+ "Callisto Morphamax 500",
+ "Callisto Morphamax 5000",
+ "Callisto Morphamax 600",
+ "Callisto Morphamax 6000 SE",
+ "Callisto Morphamax 6000 SE2",
+ "Callisto Morphamax 700",
+ "Callisto Morphamax 7000",
+ "Xiph Xlater 10000",
+ "Xiph Xlater 2000",
+ "Xiph Xlater 300",
+ "Xiph Xlater 40",
+ "Xiph Xlater 5",
+ "Xiph Xlater 50",
+ "Xiph Xlater 500",
+ "Xiph Xlater 5000",
+ "Xiph Xlater 58",
+ "",
+}
+func Test_Sort1(t *testing.T) {
testListSortedOK := []string{
"",
"10X Radonius",
@@ -167,3 +167,9 @@ func Test_Sort2(t *testing.T) {
%v`, strings.Join(testListSortedOK, "\n"), strings.Join(testListSorted, "\n"))
}
}
+
+func BenchmarkSort1(b *testing.B) {
+ for n := 0; n < b.N; n++ {
+ Sort(testList)
+ }
+}
Debdiff
File lists identical (after any substitutions)
No differences were encountered in the control files