MCPcopy Index your code
hub / github.com/tinygo-org/tinygo / hashmapIsBinaryKey

Function hashmapIsBinaryKey

compiler/map.go:250–272  ·  view source on GitHub ↗

Returns true if this key type does not contain strings, interfaces etc., so can be compared with runtime.memequal. Note that padding bytes are undef and can alter two "equal" structs being equal when compared with memequal.

(keyType types.Type)

Source from the content-addressed store, hash-verified

248// can be compared with runtime.memequal. Note that padding bytes are undef
249// and can alter two "equal" structs being equal when compared with memequal.
250func hashmapIsBinaryKey(keyType types.Type) bool {
251 switch keyType := keyType.Underlying().(type) {
252 case *types.Basic:
253 // TODO: unsafe.Pointer is also a binary key, but to support that we
254 // need to fix an issue with interp first (see
255 // https://github.com/tinygo-org/tinygo/pull/4898).
256 return keyType.Info()&(types.IsBoolean|types.IsInteger) != 0
257 case *types.Pointer:
258 return true
259 case *types.Struct:
260 for i := 0; i < keyType.NumFields(); i++ {
261 fieldType := keyType.Field(i).Type().Underlying()
262 if !hashmapIsBinaryKey(fieldType) {
263 return false
264 }
265 }
266 return true
267 case *types.Array:
268 return hashmapIsBinaryKey(keyType.Elem())
269 default:
270 return false
271 }
272}
273
274func (b *builder) zeroUndefBytes(llvmType llvm.Type, ptr llvm.Value) error {
275 // We know that hashmapIsBinaryKey is true, so we only have to handle those types that can show up there.

Callers 6

getTypeCodeMethod · 0.85
createMakeMapMethod · 0.85
createMapLookupMethod · 0.85
createMapUpdateMethod · 0.85
createMapDeleteMethod · 0.85
createMapIteratorNextMethod · 0.85

Calls 4

InfoMethod · 0.80
FieldMethod · 0.65
ElemMethod · 0.65
TypeMethod · 0.45

Tested by

no test coverage detected