Skip to content

Commit fc7f720

Browse files
committed
refactor: use sort.Slice
1 parent cf68462 commit fc7f720

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

source/driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var drivers = make(map[string]Driver)
3333
// * Drivers are supposed to be read only.
3434
// * Ideally don't load any contents (into memory) in Open or WithInstance.
3535
type Driver interface {
36-
// Open returns a a new driver instance configured with parameters
36+
// Open returns a new driver instance configured with parameters
3737
// coming from the URL string. Migrate will call this function
3838
// only once per instance.
3939
Open(url string) (Driver, error)

source/migration.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ func (i *Migrations) Append(m *Migration) (ok bool) {
6666
}
6767

6868
func (i *Migrations) buildIndex() {
69-
i.index = make(uintSlice, 0)
69+
i.index = make(uintSlice, 0, len(i.migrations))
7070
for version := range i.migrations {
7171
i.index = append(i.index, version)
7272
}
73-
sort.Sort(i.index)
73+
sort.Slice(i.index, func(x, y int) bool {
74+
return i.index[x] < i.index[y]
75+
})
7476
}
7577

7678
func (i *Migrations) First() (version uint, ok bool) {
@@ -126,18 +128,6 @@ func (i *Migrations) findPos(version uint) int {
126128

127129
type uintSlice []uint
128130

129-
func (s uintSlice) Len() int {
130-
return len(s)
131-
}
132-
133-
func (s uintSlice) Swap(i, j int) {
134-
s[i], s[j] = s[j], s[i]
135-
}
136-
137-
func (s uintSlice) Less(i, j int) bool {
138-
return s[i] < s[j]
139-
}
140-
141131
func (s uintSlice) Search(x uint) int {
142132
return sort.Search(len(s), func(i int) bool { return s[i] >= x })
143133
}

0 commit comments

Comments
 (0)