@@ -55,17 +55,23 @@ func parsePackage(ctx context.Context, fSet *token.FileSet, pat string) ([]*ast.
55
55
}
56
56
57
57
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
+ }
62
66
}
63
- min , max := []rune (terms [0 ]), []rune (terms [len (terms )- 1 ])
67
+
68
+ minR , maxR := []rune (min ), []rune (max )
64
69
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 ] {
66
71
i ++
67
72
}
68
- return string (min [:i ])
73
+
74
+ return min [:i ]
69
75
}
70
76
71
77
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)
99
105
for _ , f := range files {
100
106
fns = append (fns , fSet .Position (f .Pos ()).Filename )
101
107
}
102
- sort .Strings (fns )
103
108
104
109
switch len (fns ) {
105
110
case 0 :
@@ -111,6 +116,7 @@ func logLoadedFiles(ctx context.Context, fSet *token.FileSet, files []*ast.File)
111
116
for i := range fns {
112
117
fns [i ] = fns [i ][len (prefix ):]
113
118
}
119
+ sort .Strings (fns )
114
120
ctxLogf (ctx , `files_found=%d files=%v{%v}` , len (fns ), prefix , strings .Join (fns , "," ))
115
121
}
116
122
}
0 commit comments