1// Copyright 2019 The Go Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5//go:build !go1.12 6// +build !go1.12 7 8package impl 9 10import "reflect" 11 12type mapIter struct { 13 v reflect.Value 14 keys []reflect.Value 15} 16 17// mapRange provides a less-efficient equivalent to 18// the Go 1.12 reflect.Value.MapRange method. 19func mapRange(v reflect.Value) *mapIter { 20 return &mapIter{v: v} 21} 22 23func (i *mapIter) Next() bool { 24 if i.keys == nil { 25 i.keys = i.v.MapKeys() 26 } else { 27 i.keys = i.keys[1:] 28 } 29 return len(i.keys) > 0 30} 31 32func (i *mapIter) Key() reflect.Value { 33 return i.keys[0] 34} 35 36func (i *mapIter) Value() reflect.Value { 37 return i.v.MapIndex(i.keys[0]) 38} 39