MCPcopy Create free account
hub / github.com/google/gapid / IterateMap

Method IterateMap

gapil/compiler/map.go:494–509  ·  view source on GitHub ↗

IterateMap emits a map iteration calling cb for each element in the map where: i is a pointer to the sequential index of the element starting from 0 of type idxTy. k is a pointer to the element key. v is a pointer to the element value.

(s *S, mapPtr *codegen.Value, idxTy semantic.Type, cb func(i, k, v *codegen.Value))

Source from the content-addressed store, hash-verified

492// k is a pointer to the element key.
493// v is a pointer to the element value.
494func (c *C) IterateMap(s *S, mapPtr *codegen.Value, idxTy semantic.Type, cb func(i, k, v *codegen.Value)) {
495 capacity := mapPtr.Index(0, MapCapacity).Load()
496 elPtr := mapPtr.Index(0, MapElements).Load()
497 iTy := c.T.Target(idxTy)
498 i := s.LocalInit("i", s.Scalar(0).Cast(iTy))
499 s.ForN(capacity.Cast(iTy), func(s *S, it *codegen.Value) *codegen.Value {
500 used := elPtr.Index(it, "used").Load()
501 s.If(s.Equal(used, s.Scalar(mapElementFull)), func(s *S) {
502 k := elPtr.Index(it, "k")
503 v := elPtr.Index(it, "v")
504 cb(i, k, v)
505 i.Store(s.Add(i.Load(), s.Scalar(1).Cast(iTy)))
506 })
507 return nil
508 })
509}

Callers 3

mapIterationMethod · 0.95
encodeValueMethod · 0.80
implementClonesMethod · 0.80

Calls 11

LocalInitMethod · 0.80
LoadMethod · 0.65
IndexMethod · 0.65
StoreMethod · 0.65
AddMethod · 0.65
TargetMethod · 0.45
CastMethod · 0.45
ScalarMethod · 0.45
ForNMethod · 0.45
IfMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected