@@ -83,46 +83,48 @@ type matcherFunc func(chunks []string) (int, float64)
83
83
// []string{"myType.field"} or []string{"myType.", "field"}.
84
84
//
85
85
// See the comment for symbolCollector for more information.
86
- type symbolizer func (name string , pkg Metadata , m matcherFunc ) ([]string , float64 )
86
+ //
87
+ // The space argument is an empty slice with spare capacity that may be used
88
+ // to allocate the result.
89
+ type symbolizer func (space []string , name string , pkg Metadata , m matcherFunc ) ([]string , float64 )
87
90
88
- func fullyQualifiedSymbolMatch (name string , pkg Metadata , matcher matcherFunc ) ([]string , float64 ) {
89
- _ , score := dynamicSymbolMatch (name , pkg , matcher )
90
- if score > 0 {
91
- return []string {pkg .PackagePath (), "." , name }, score
91
+ func fullyQualifiedSymbolMatch (space []string , name string , pkg Metadata , matcher matcherFunc ) ([]string , float64 ) {
92
+ if _ , score := dynamicSymbolMatch (space , name , pkg , matcher ); score > 0 {
93
+ return append (space , pkg .PackagePath (), "." , name ), score
92
94
}
93
95
return nil , 0
94
96
}
95
97
96
- func dynamicSymbolMatch (name string , pkg Metadata , matcher matcherFunc ) ([]string , float64 ) {
98
+ func dynamicSymbolMatch (space [] string , name string , pkg Metadata , matcher matcherFunc ) ([]string , float64 ) {
97
99
var score float64
98
100
99
101
endsInPkgName := strings .HasSuffix (pkg .PackagePath (), pkg .PackageName ())
100
102
101
103
// If the package path does not end in the package name, we need to check the
102
104
// package-qualified symbol as an extra pass first.
103
105
if ! endsInPkgName {
104
- pkgQualified := [] string { pkg .PackageName (), "." , name }
106
+ pkgQualified := append ( space , pkg .PackageName (), "." , name )
105
107
idx , score := matcher (pkgQualified )
106
108
nameStart := len (pkg .PackageName ()) + 1
107
109
if score > 0 {
108
110
// If our match is contained entirely within the unqualified portion,
109
111
// just return that.
110
112
if idx >= nameStart {
111
- return [] string { name } , score
113
+ return append ( space , name ) , score
112
114
}
113
115
// Lower the score for matches that include the package name.
114
116
return pkgQualified , score * 0.8
115
117
}
116
118
}
117
119
118
120
// Now try matching the fully qualified symbol.
119
- fullyQualified := [] string { pkg .PackagePath (), "." , name }
121
+ fullyQualified := append ( space , pkg .PackagePath (), "." , name )
120
122
idx , score := matcher (fullyQualified )
121
123
122
124
// As above, check if we matched just the unqualified symbol name.
123
125
nameStart := len (pkg .PackagePath ()) + 1
124
126
if idx >= nameStart {
125
- return [] string { name } , score
127
+ return append ( space , name ) , score
126
128
}
127
129
128
130
// If our package path ends in the package name, we'll have skipped the
@@ -131,7 +133,7 @@ func dynamicSymbolMatch(name string, pkg Metadata, matcher matcherFunc) ([]strin
131
133
if endsInPkgName && idx >= 0 {
132
134
pkgStart := len (pkg .PackagePath ()) - len (pkg .PackageName ())
133
135
if idx >= pkgStart {
134
- return [] string { pkg .PackageName (), "." , name } , score
136
+ return append ( space , pkg .PackageName (), "." , name ) , score
135
137
}
136
138
}
137
139
@@ -140,8 +142,8 @@ func dynamicSymbolMatch(name string, pkg Metadata, matcher matcherFunc) ([]strin
140
142
return fullyQualified , score * 0.6
141
143
}
142
144
143
- func packageSymbolMatch (name string , pkg Metadata , matcher matcherFunc ) ([]string , float64 ) {
144
- qualified := [] string { pkg .PackageName (), "." , name }
145
+ func packageSymbolMatch (space [] string , name string , pkg Metadata , matcher matcherFunc ) ([]string , float64 ) {
146
+ qualified := append ( space , pkg .PackageName (), "." , name )
145
147
if _ , s := matcher (qualified ); s > 0 {
146
148
return qualified , s
147
149
}
@@ -387,8 +389,9 @@ type symbolFile struct {
387
389
388
390
// matchFile scans a symbol file and adds matching symbols to the store.
389
391
func matchFile (store * symbolStore , symbolizer symbolizer , matcher matcherFunc , roots []string , i symbolFile ) {
392
+ space := make ([]string , 0 , 3 )
390
393
for _ , sym := range i .syms {
391
- symbolParts , score := symbolizer (sym .Name , i .md , matcher )
394
+ symbolParts , score := symbolizer (space , sym .Name , i .md , matcher )
392
395
393
396
// Check if the score is too low before applying any downranking.
394
397
if store .tooLow (score ) {
0 commit comments