You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

39 lines
739 B

  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. //go:build !go1.12
  5. // +build !go1.12
  6. package impl
  7. import "reflect"
  8. type mapIter struct {
  9. v reflect.Value
  10. keys []reflect.Value
  11. }
  12. // mapRange provides a less-efficient equivalent to
  13. // the Go 1.12 reflect.Value.MapRange method.
  14. func mapRange(v reflect.Value) *mapIter {
  15. return &mapIter{v: v}
  16. }
  17. func (i *mapIter) Next() bool {
  18. if i.keys == nil {
  19. i.keys = i.v.MapKeys()
  20. } else {
  21. i.keys = i.keys[1:]
  22. }
  23. return len(i.keys) > 0
  24. }
  25. func (i *mapIter) Key() reflect.Value {
  26. return i.keys[0]
  27. }
  28. func (i *mapIter) Value() reflect.Value {
  29. return i.v.MapIndex(i.keys[0])
  30. }