diff --git a/src/Expr.cc b/src/Expr.cc index fe32e54df8..1e01d7bc39 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -2550,7 +2550,7 @@ void IndexExpr::Delete(Frame* f) if ( ! v2 ) return; - v1->AsTableVal()->Delete(v2.get()); + v1->AsTableVal()->Remove(*v2); } IntrusivePtr IndexExpr::MakeLvalue() diff --git a/src/Val.cc b/src/Val.cc index a11c26b0f7..bfa3ed9a37 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1657,7 +1657,7 @@ bool TableVal::RemoveFrom(Val* val) const // OTOH, they are both the same type, so as long as // we don't have hash keys that are keyed per dictionary, // it should work ... - t->Delete(k); + t->Remove(k); delete k; } @@ -2089,16 +2089,16 @@ void TableVal::CallChangeFunc(const Val* index, Val* old_value, OnChangeType tpe in_change_func = false; } -IntrusivePtr TableVal::Delete(const Val* index) +IntrusivePtr TableVal::Remove(const Val& index) { - HashKey* k = ComputeHash(*index); + HashKey* k = ComputeHash(index); TableEntryVal* v = k ? AsNonConstTable()->RemoveEntry(k) : nullptr; IntrusivePtr va; if ( v ) va = v->GetVal() ? v->GetVal() : IntrusivePtr{NewRef{}, this}; - if ( subnets && ! subnets->Remove(index) ) + if ( subnets && ! subnets->Remove(&index) ) reporter->InternalWarning("index not in prefix table"); delete k; @@ -2107,12 +2107,12 @@ IntrusivePtr TableVal::Delete(const Val* index) Modified(); if ( change_func ) - CallChangeFunc(index, va.get(), ELEMENT_REMOVED); + CallChangeFunc(&index, va.get(), ELEMENT_REMOVED); return va; } -IntrusivePtr TableVal::Delete(const HashKey* k) +IntrusivePtr TableVal::Remove(const HashKey* k) { TableEntryVal* v = AsNonConstTable()->RemoveEntry(k); IntrusivePtr va; diff --git a/src/Val.h b/src/Val.h index 42210518ea..c00dc07afc 100644 --- a/src/Val.h +++ b/src/Val.h @@ -875,9 +875,31 @@ public: // Returns the index corresponding to the given HashKey. IntrusivePtr RecoverIndex(const HashKey* k) const; - // Returns the element if it was in the table, false otherwise. - IntrusivePtr Delete(const Val* index); - IntrusivePtr Delete(const HashKey* k); + /** + * Remove an element from the table and return it. + * @param index The index to remove. + * @return The value associated with the index if it exists, else nullptr. + * For a sets that don't really contain associated values, a placeholder + * value is returned to differentiate it from non-existent index (nullptr), + * but otherwise has no meaning in relation to the set's contents. + */ + IntrusivePtr Remove(const Val& index); + + /** + * Same as Remove(const Val&), but uses a precomputed hash key. + * @param k The hash key to lookup. This method takes ownership of + * deleting it. + * @return Same as Remove(const Val&). + */ + IntrusivePtr Remove(const HashKey* k); + + [[deprecated("Remove in v4.1. Use Remove().")]] + Val* Delete(const Val* index) + { return Remove(*index).release(); } + + [[deprecated("Remove in v4.1. Use Remove().")]] + Val* Delete(const HashKey* k) + { return Remove(k).release(); } // Returns a ListVal representation of the table (which must be a set). IntrusivePtr ToListVal(TypeTag t = TYPE_ANY) const; diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 9788fbd802..1191b6233f 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1371,7 +1371,7 @@ void Manager::EndCurrentSend(ReaderFrontend* reader) SendEvent(stream->event, 4, stream->description->Ref(), ev->Ref(), predidx->Ref(), val->Ref()); - stream->tab->Delete(ih->idxkey); + stream->tab->Remove(ih->idxkey); stream->lastDict->Remove(lastDictIdxKey); // delete in next line delete lastDictIdxKey; delete(ih); @@ -1737,7 +1737,7 @@ bool Manager::Delete(ReaderFrontend* reader, Value* *vals) // only if stream = true -> no streaming if ( streamresult ) { - if ( ! stream->tab->Delete(idxval) ) + if ( ! stream->tab->Remove(*idxval) ) Warning(i, "Internal error while deleting values from input table"); } }