@@ -39,8 +39,8 @@ struct DictBase : public MLCDict {
3939 inline static void WithCapacity (TDictObj *self, int64_t new_cap);
4040 inline static KVPair *InsertOrLookup (TDictObj *self, Any key);
4141 inline static KVPair *TryInsertOrLookup (TDictObj *self, MLCAny *key);
42- inline static void Erase (TDictObj *self, const Any &key);
43- inline static void Erase (TDictObj *self, int64_t index);
42+ inline static Any Erase (TDictObj *self, const Any &key);
43+ inline static void _Erase (TDictObj *self, int64_t index);
4444 inline static Any &At (TDictObj *self, const Any &key);
4545 inline static const Any &At (const TDictObj *self, const Any &key);
4646 inline static Any &Bracket (TDictObj *self, const Any &key) {
@@ -52,6 +52,8 @@ struct DictBase : public MLCDict {
5252 inline static BlockIter Prev (const TDictObj *self, BlockIter iter);
5353 inline static void New (int32_t num_args, const AnyView *args, Any *any_ret);
5454 inline static Any GetItem (TDictObj *self, Any key) { return self->at (key); }
55+ inline static void SetItem (TDictObj *self, Any key, Any value) { (*self)[key] = value; }
56+ inline static Any DelItem (TDictObj *self, Any key) { return Erase (self, key); }
5557 inline static Any GetKey (TDictObj *self, int64_t i) { return IterStateMut{self, i}.At ().first ; }
5658 inline static Any GetValue (TDictObj *self, int64_t i) { return IterStateMut{self, i}.At ().second ; }
5759 inline static int64_t Advance (TDictObj *self, int64_t i) { return IterStateMut{self, i}.Add ().i ; }
@@ -298,17 +300,19 @@ inline DictBase::KVPair *DictBase::Accessor<TDictObj>::TryInsertOrLookup(TDictOb
298300}
299301
300302template <typename TDictObj> //
301- inline void DictBase::Accessor<TDictObj>::Erase(TDictObj *self, const Any &key) {
303+ inline Any DictBase::Accessor<TDictObj>::Erase(TDictObj *self, const Any &key) {
302304 BlockIter iter = TSelf::Lookup (self, key);
303305 if (!iter.IsNone ()) {
304- TSelf::Erase (self, iter.i );
305- } else {
306- MLC_THROW (KeyError) << key ;
306+ Any ret = static_cast <Any &>( iter.Data (). second );
307+ TSelf::_Erase (self, iter. i );
308+ return ret ;
307309 }
310+ MLC_THROW (KeyError) << key;
311+ MLC_UNREACHABLE ();
308312}
309313
310314template <typename TDictObj> //
311- inline void DictBase::Accessor<TDictObj>::Erase (TDictObj *self, int64_t index) {
315+ inline void DictBase::Accessor<TDictObj>::_Erase (TDictObj *self, int64_t index) {
312316 DictBase *self_base = static_cast <DictBase *>(self);
313317 BlockIter iter = BlockIter::FromIndex (self_base, index);
314318 if (uint64_t offset = iter.Offset (); offset != 0 ) {
0 commit comments