bencode: Simplify `(*Decoder).parseListInterface()` (#656)

Preserve as much type as possible (it'll be converted to an `interface{}` anyway, but we can return `[]interface{}` instead of `{}interface` here).
This commit is contained in:
YenForYang 2021-09-17 21:42:20 -05:00 committed by GitHub
parent f3a9ea5aa9
commit d43769dc15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 12 deletions

View File

@ -661,18 +661,12 @@ func (d *Decoder) parseDictInterface() interface{} {
return dict
}
func (d *Decoder) parseListInterface() interface{} {
var list []interface{}
for {
valuei, ok := d.parseValueInterface()
if !ok {
break
}
func (d *Decoder) parseListInterface() (list []interface{}) {
list = []interface{}{}
valuei, ok := d.parseValueInterface()
for ok {
list = append(list, valuei)
valuei, ok = d.parseValueInterface()
}
if list == nil {
list = make([]interface{}, 0)
}
return list
return
}