MCPcopy
hub / github.com/tinygo-org/tinygo / createMapDelete

Method createMapDelete

compiler/map.go:152–180  ·  view source on GitHub ↗

createMapDelete deletes a key from a map by calling the appropriate runtime function. It is the implementation of the Go delete() builtin.

(keyType types.Type, m, key llvm.Value, pos token.Pos)

Source from the content-addressed store, hash-verified

150// createMapDelete deletes a key from a map by calling the appropriate runtime
151// function. It is the implementation of the Go delete() builtin.
152func (b *builder) createMapDelete(keyType types.Type, m, key llvm.Value, pos token.Pos) error {
153 origKeyType := keyType
154 keyType = keyType.Underlying()
155 if t, ok := keyType.(*types.Basic); ok && t.Info()&types.IsString != 0 {
156 // key is a string
157 params := []llvm.Value{m, key}
158 b.createRuntimeCall("hashmapStringDelete", params, "")
159 return nil
160 } else if hashmapIsBinaryKey(keyType) {
161 keyAlloca, keySize := b.createTemporaryAlloca(key.Type(), "hashmap.key")
162 b.CreateStore(key, keyAlloca)
163 b.zeroUndefBytes(b.getLLVMType(keyType), keyAlloca)
164 params := []llvm.Value{m, keyAlloca}
165 b.createRuntimeCall("hashmapBinaryDelete", params, "")
166 b.emitLifetimeEnd(keyAlloca, keySize)
167 return nil
168 } else {
169 // Key is not trivially comparable, so compare it as an interface
170 // instead.
171 itfKey := key
172 if _, ok := keyType.(*types.Interface); !ok {
173 // Not already an interface, so convert it to an interface first.
174 itfKey = b.createMakeInterface(key, origKeyType, pos)
175 }
176 params := []llvm.Value{m, itfKey}
177 b.createRuntimeCall("hashmapInterfaceDelete", params, "")
178 return nil
179 }
180}
181
182// Clear the given map.
183func (b *builder) createMapClear(m llvm.Value) {

Callers 1

createBuiltinMethod · 0.95

Calls 9

createRuntimeCallMethod · 0.95
createTemporaryAllocaMethod · 0.95
zeroUndefBytesMethod · 0.95
emitLifetimeEndMethod · 0.95
createMakeInterfaceMethod · 0.95
hashmapIsBinaryKeyFunction · 0.85
InfoMethod · 0.80
getLLVMTypeMethod · 0.80
TypeMethod · 0.45

Tested by

no test coverage detected