@@ -1102,20 +1102,9 @@ func hashmapNewIterator() unsafe.Pointer
11021102func hashmapNext (m unsafe.Pointer , it unsafe.Pointer , key , value unsafe.Pointer ) bool
11031103
11041104func (v Value ) MapRange () * MapIter {
1105- if v .Kind () != Map {
1106- panic (& ValueError {Method : "MapRange" , Kind : v .Kind ()})
1107- }
1108-
1109- keyType := v .typecode .key ()
1110-
1111- keyTypeIsEmptyInterface := keyType .Kind () == Interface && keyType .NumMethod () == 0
1112- shouldUnpackInterface := ! keyTypeIsEmptyInterface && keyType .Kind () != String && ! keyType .isBinary ()
1113-
1114- return & MapIter {
1115- m : v ,
1116- it : hashmapNewIterator (),
1117- unpackKeyInterface : shouldUnpackInterface ,
1118- }
1105+ iter := & MapIter {}
1106+ iter .Reset (v )
1107+ return iter
11191108}
11201109
11211110type MapIter struct {
@@ -1142,6 +1131,10 @@ func (it *MapIter) Key() Value {
11421131 return it .key .Elem ()
11431132}
11441133
1134+ func (v Value ) SetIterKey (iter * MapIter ) {
1135+ v .Set (iter .Key ())
1136+ }
1137+
11451138func (it * MapIter ) Value () Value {
11461139 if ! it .valid {
11471140 panic ("reflect.MapIter.Value called on invalid iterator" )
@@ -1150,6 +1143,10 @@ func (it *MapIter) Value() Value {
11501143 return it .val .Elem ()
11511144}
11521145
1146+ func (v Value ) SetIterValue (iter * MapIter ) {
1147+ v .Set (iter .Value ())
1148+ }
1149+
11531150func (it * MapIter ) Next () bool {
11541151 it .key = New (it .m .typecode .Key ())
11551152 it .val = New (it .m .typecode .Elem ())
@@ -1158,6 +1155,23 @@ func (it *MapIter) Next() bool {
11581155 return it .valid
11591156}
11601157
1158+ func (iter * MapIter ) Reset (v Value ) {
1159+ if v .Kind () != Map {
1160+ panic (& ValueError {Method : "MapRange" , Kind : v .Kind ()})
1161+ }
1162+
1163+ keyType := v .typecode .key ()
1164+
1165+ keyTypeIsEmptyInterface := keyType .Kind () == Interface && keyType .NumMethod () == 0
1166+ shouldUnpackInterface := ! keyTypeIsEmptyInterface && keyType .Kind () != String && ! keyType .isBinary ()
1167+
1168+ * iter = MapIter {
1169+ m : v ,
1170+ it : hashmapNewIterator (),
1171+ unpackKeyInterface : shouldUnpackInterface ,
1172+ }
1173+ }
1174+
11611175func (v Value ) Set (x Value ) {
11621176 v .checkAddressable ()
11631177 v .checkRO ()
0 commit comments