Procházet zdrojové kódy

codec: Limit initial capacity of new maps to the MaxInitLen

Kudos to @akalin-keybase for finding it.
Ugorji Nwoke před 7 roky
rodič
revize
9d693b80ac
1 změnil soubory, kde provedl 2 přidání a 1 odebrání
  1. 2 1
      codec/decode.go

+ 2 - 1
codec/decode.go

@@ -1505,7 +1505,8 @@ func (d *Decoder) kMap(f *codecFnInfo, rv reflect.Value) {
 	elemsep := d.esep
 	ti := f.ti
 	if rv.IsNil() {
-		rv.Set(makeMapReflect(ti.rt, containerLen))
+		rvlen := decInferLen(containerLen, d.h.MaxInitLen, int(ti.key.Size()+ti.elem.Size()))
+		rv.Set(makeMapReflect(ti.rt, rvlen))
 	}
 
 	if containerLen == 0 {