@@ -39,8 +39,8 @@ struct DictBase : public MLCDict {
39
39
inline static void WithCapacity (TDictObj *self, int64_t new_cap);
40
40
inline static KVPair *InsertOrLookup (TDictObj *self, Any key);
41
41
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);
44
44
inline static Any &At (TDictObj *self, const Any &key);
45
45
inline static const Any &At (const TDictObj *self, const Any &key);
46
46
inline static Any &Bracket (TDictObj *self, const Any &key) {
@@ -52,6 +52,8 @@ struct DictBase : public MLCDict {
52
52
inline static BlockIter Prev (const TDictObj *self, BlockIter iter);
53
53
inline static void New (int32_t num_args, const AnyView *args, Any *any_ret);
54
54
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); }
55
57
inline static Any GetKey (TDictObj *self, int64_t i) { return IterStateMut{self, i}.At ().first ; }
56
58
inline static Any GetValue (TDictObj *self, int64_t i) { return IterStateMut{self, i}.At ().second ; }
57
59
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
298
300
}
299
301
300
302
template <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) {
302
304
BlockIter iter = TSelf::Lookup (self, key);
303
305
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 ;
307
309
}
310
+ MLC_THROW (KeyError) << key;
311
+ MLC_UNREACHABLE ();
308
312
}
309
313
310
314
template <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) {
312
316
DictBase *self_base = static_cast <DictBase *>(self);
313
317
BlockIter iter = BlockIter::FromIndex (self_base, index);
314
318
if (uint64_t offset = iter.Offset (); offset != 0 ) {
0 commit comments