]> Sergey Matveev's repositories - btrtrc.git/commitdiff
bencode: Simplify `(*Decoder).parseListInterface()` (#656)
authorYenForYang <YenForYang@users.noreply.github.com>
Sat, 18 Sep 2021 02:42:20 +0000 (21:42 -0500)
committerGitHub <noreply@github.com>
Sat, 18 Sep 2021 02:42:20 +0000 (12:42 +1000)
Preserve as much type as possible (it'll be converted to an `interface{}` anyway, but we can return `[]interface{}` instead of `{}interface` here).

bencode/decode.go

index 08d7861c7e6a03cadc766e61bc700b86edf64cab..9c42578a7ed7387a5783ab07db61a016e96b74cb 100644 (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
 }