Val: TableVal::Delete() returns IntrusivePtr

This commit is contained in:
Max Kellermann 2020-03-04 20:58:38 +01:00
parent 6495193aae
commit d2961c72e1
4 changed files with 10 additions and 12 deletions

View file

@ -2581,7 +2581,7 @@ void IndexExpr::Delete(Frame* f)
if ( ! v2 ) if ( ! v2 )
return; return;
Unref(v1->AsTableVal()->Delete(v2.get())); v1->AsTableVal()->Delete(v2.get());
} }
IntrusivePtr<Expr> IndexExpr::MakeLvalue() IntrusivePtr<Expr> IndexExpr::MakeLvalue()

View file

@ -1598,7 +1598,7 @@ int TableVal::RemoveFrom(Val* val) const
// OTOH, they are both the same type, so as long as // OTOH, they are both the same type, so as long as
// we don't have hash keys that are keyed per dictionary, // we don't have hash keys that are keyed per dictionary,
// it should work ... // it should work ...
Unref(t->Delete(k)); t->Delete(k);
delete k; delete k;
} }
@ -2000,7 +2000,7 @@ void TableVal::CallChangeFunc(const Val* index, Val* old_value, OnChangeType tpe
in_change_func = false; in_change_func = false;
} }
Val* TableVal::Delete(const Val* index) IntrusivePtr<Val> TableVal::Delete(const Val* index)
{ {
HashKey* k = ComputeHash(index); HashKey* k = ComputeHash(index);
TableEntryVal* v = k ? AsNonConstTable()->RemoveEntry(k) : 0; TableEntryVal* v = k ? AsNonConstTable()->RemoveEntry(k) : 0;
@ -2017,10 +2017,10 @@ Val* TableVal::Delete(const Val* index)
if ( change_func ) if ( change_func )
CallChangeFunc(index, va.get(), ELEMENT_REMOVED); CallChangeFunc(index, va.get(), ELEMENT_REMOVED);
return va.release(); return va;
} }
Val* TableVal::Delete(const HashKey* k) IntrusivePtr<Val> TableVal::Delete(const HashKey* k)
{ {
TableEntryVal* v = AsNonConstTable()->RemoveEntry(k); TableEntryVal* v = AsNonConstTable()->RemoveEntry(k);
IntrusivePtr<Val> va{NewRef{}, v ? (v->Value() ? v->Value() : this) : nullptr}; IntrusivePtr<Val> va{NewRef{}, v ? (v->Value() ? v->Value() : this) : nullptr};
@ -2042,7 +2042,7 @@ Val* TableVal::Delete(const HashKey* k)
CallChangeFunc(index.get(), va.get(), ELEMENT_REMOVED); CallChangeFunc(index.get(), va.get(), ELEMENT_REMOVED);
} }
return va.release(); return va;
} }
ListVal* TableVal::ConvertToList(TypeTag t) const ListVal* TableVal::ConvertToList(TypeTag t) const

View file

@ -769,8 +769,8 @@ public:
ListVal* RecoverIndex(const HashKey* k) const; ListVal* RecoverIndex(const HashKey* k) const;
// Returns the element if it was in the table, false otherwise. // Returns the element if it was in the table, false otherwise.
Val* Delete(const Val* index); IntrusivePtr<Val> Delete(const Val* index);
Val* Delete(const HashKey* k); IntrusivePtr<Val> Delete(const HashKey* k);
// Returns a ListVal representation of the table (which must be a set). // Returns a ListVal representation of the table (which must be a set).
ListVal* ConvertToList(TypeTag t=TYPE_ANY) const; ListVal* ConvertToList(TypeTag t=TYPE_ANY) const;

View file

@ -1423,7 +1423,7 @@ void Manager::EndCurrentSend(ReaderFrontend* reader)
if ( ev ) if ( ev )
Unref(ev); Unref(ev);
Unref(stream->tab->Delete(ih->idxkey)); stream->tab->Delete(ih->idxkey);
stream->lastDict->Remove(lastDictIdxKey); // delete in next line stream->lastDict->Remove(lastDictIdxKey); // delete in next line
delete lastDictIdxKey; delete lastDictIdxKey;
delete(ih); delete(ih);
@ -1790,12 +1790,10 @@ bool Manager::Delete(ReaderFrontend* reader, Value* *vals)
// only if stream = true -> no streaming // only if stream = true -> no streaming
if ( streamresult ) if ( streamresult )
{ {
Val* retptr = stream->tab->Delete(idxval); auto retptr = stream->tab->Delete(idxval);
success = ( retptr != 0 ); success = ( retptr != 0 );
if ( ! success ) if ( ! success )
Warning(i, "Internal error while deleting values from input table"); Warning(i, "Internal error while deleting values from input table");
else
Unref(retptr);
} }
} }