Skip to content

Commit 23e0b84

Browse files
committed
fixes
1 parent 4f3f7e6 commit 23e0b84

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

types.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func (t *types) AddNoRepeat(n Type) {
189189
}
190190
name := n.Name()
191191
i := t.SearchIndex(name)
192-
tt := t.Index(i - 1)
192+
tt := t.Index(i)
193193
if tt == nil || tt.Name() != name {
194194
t.add(i, n)
195195
}
@@ -198,29 +198,21 @@ func (t *types) AddNoRepeat(n Type) {
198198

199199
func (t *types) Search(name string) (Type, bool) {
200200
i := t.SearchIndex(name)
201-
if i == 0 {
202-
return nil, false
203-
}
204-
tt := t.Index(i - 1)
201+
tt := t.Index(i)
205202
if tt == nil || tt.Name() != name {
206203
return nil, false
207204
}
208205
return tt, true
209206
}
210207

211208
func (t *types) SearchIndex(name string) int {
212-
i := sort.Search(t.Len(), func(i int) bool {
213-
d := t.Index(i)
214-
if d == nil {
215-
return false
216-
}
217-
return d.Name() < name
209+
return sort.Search(t.Len(), func(i int) bool {
210+
return t.Index(i).Name() <= name
218211
})
219-
return i
220212
}
221213

222214
func (t *types) Index(i int) Type {
223-
if i >= t.Len() || i < 0 {
215+
if i >= t.Len() {
224216
return nil
225217
}
226218
return (*t)[i]

0 commit comments

Comments
 (0)