New conditional for adding key/value pairs to maps.
When adding MultiDeviceKeys and their values into MultiDevice maps, make sure the keys and values have not already been added. This ensures that preexisting key/value pairs are not overridden. PiperOrigin-RevId: 206942766 Change-Id: I9d85f38eb59ba59f0305e6614a52690608944981
This commit is contained in:
parent
413bfb39a9
commit
6b87378634
|
@ -183,6 +183,14 @@ func (m *MultiDevice) Load(key MultiDeviceKey, value uint64) bool {
|
|||
m.rcache = make(map[uint64]MultiDeviceKey)
|
||||
}
|
||||
|
||||
if val, exists := m.cache[key]; exists && val != value {
|
||||
return false
|
||||
}
|
||||
if k, exists := m.rcache[value]; exists && k != key {
|
||||
// Should never happen.
|
||||
panic("MultiDevice's caches are inconsistent")
|
||||
}
|
||||
|
||||
// Cache value at key.
|
||||
m.cache[key] = value
|
||||
|
||||
|
|
Loading…
Reference in New Issue