diff --git a/map.go b/map.go index b6933065..aaf9b7a6 100644 --- a/map.go +++ b/map.go @@ -4966,19 +4966,19 @@ func (m *OrderedMap) Storable(_ SlabStorage, _ Address, maxInlineSize uint64) (S inlined := m.root.Inlined() inlinable := m.root.Inlinable(maxInlineSize) - if inlinable && inlined { + switch { + + case inlinable && inlined: // Root slab is inlinable and was inlined. // Return root slab as storable, no size adjustment and change to storage. return m.root, nil - } - if !inlinable && !inlined { + case !inlinable && !inlined: // Root slab is not inlinable and was not inlined. // Return root slab as storable, no size adjustment and change to storage. return SlabIDStorable(m.SlabID()), nil - } - if inlinable && !inlined { + case inlinable && !inlined: // Root slab is inlinable and was NOT inlined. // Inline root data slab. @@ -5005,32 +5005,37 @@ func (m *OrderedMap) Storable(_ SlabStorage, _ Address, maxInlineSize uint64) (S rootDataSlab.inlined = true return rootDataSlab, nil - } - // here, root slab is NOT inlinable and was inlined. + case !inlinable && inlined: - // Un-inline root slab. + // Root slab is NOT inlinable and was inlined. - // Inlined root slab must be data slab. - rootDataSlab, ok := m.root.(*MapDataSlab) - if !ok { - return nil, NewFatalError(fmt.Errorf("unexpected inlined map slab type %T", m.root)) - } + // Un-inline root slab. - // Update root data slab size from inlined to not inlined. - rootDataSlab.header.size = mapRootDataSlabPrefixSize + rootDataSlab.elements.Size() + // Inlined root slab must be data slab. + rootDataSlab, ok := m.root.(*MapDataSlab) + if !ok { + return nil, NewFatalError(fmt.Errorf("unexpected inlined map slab type %T", m.root)) + } - // Update root data slab inlined status. - rootDataSlab.inlined = false + // Update root data slab size from inlined to not inlined. + rootDataSlab.header.size = mapRootDataSlabPrefixSize + rootDataSlab.elements.Size() - // Store root slab in storage - err := m.Storage.Store(m.SlabID(), m.root) - if err != nil { - // Wrap err as external error (if needed) because err is returned by SlabStorage interface. - return nil, wrapErrorfAsExternalErrorIfNeeded(err, fmt.Sprintf("failed to store slab %s", m.SlabID())) - } + // Update root data slab inlined status. + rootDataSlab.inlined = false + + // Store root slab in storage + err := m.Storage.Store(m.SlabID(), m.root) + if err != nil { + // Wrap err as external error (if needed) because err is returned by SlabStorage interface. + return nil, wrapErrorfAsExternalErrorIfNeeded(err, fmt.Sprintf("failed to store slab %s", m.SlabID())) + } + + return SlabIDStorable(m.SlabID()), nil - return SlabIDStorable(m.SlabID()), nil + default: + panic("not reachable") + } } func (m *OrderedMap) Count() uint64 {