Skip to content

Commit d172380

Browse files
committed
Silly fix
1 parent ff00f53 commit d172380

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

goquote.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,23 @@ func parsePackage(ctx context.Context, fSet *token.FileSet, pat string) ([]*ast.
5555
}
5656

5757
func commonPrefix(terms []string) string {
58-
if !sort.StringsAreSorted(terms) {
59-
cp := make([]string, len(terms))
60-
copy(cp, terms)
61-
terms = cp
58+
var min, max string
59+
for _, t := range terms {
60+
if min == "" || t < min {
61+
min = t
62+
}
63+
if max == "" || t > max {
64+
max = t
65+
}
6266
}
63-
min, max := []rune(terms[0]), []rune(terms[len(terms)-1])
67+
68+
minR, maxR := []rune(min), []rune(max)
6469
var i int
65-
for i < len(min) && i < len(max) && min[i] != max[i] {
70+
for i < len(minR) && i < len(maxR) && minR[i] == maxR[i] {
6671
i++
6772
}
68-
return string(min[:i])
73+
74+
return min[:i]
6975
}
7076

7177
func parseDir(ctx context.Context, fSet *token.FileSet, pat string) ([]*ast.File, error) {
@@ -99,7 +105,6 @@ func logLoadedFiles(ctx context.Context, fSet *token.FileSet, files []*ast.File)
99105
for _, f := range files {
100106
fns = append(fns, fSet.Position(f.Pos()).Filename)
101107
}
102-
sort.Strings(fns)
103108

104109
switch len(fns) {
105110
case 0:
@@ -111,6 +116,7 @@ func logLoadedFiles(ctx context.Context, fSet *token.FileSet, files []*ast.File)
111116
for i := range fns {
112117
fns[i] = fns[i][len(prefix):]
113118
}
119+
sort.Strings(fns)
114120
ctxLogf(ctx, `files_found=%d files=%v{%v}`, len(fns), prefix, strings.Join(fns, ","))
115121
}
116122
}

0 commit comments

Comments
 (0)