From 3962810e4b77670920835ded770f0feafcc04ba3 Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Mon, 5 Aug 2024 09:14:55 +0100 Subject: [PATCH] ListVal method to clear the list to allow reusing w/o new construction --- src/Type.h | 3 +++ src/Val.h | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/Type.h b/src/Type.h index 7261a445f4..da455ee6c3 100644 --- a/src/Type.h +++ b/src/Type.h @@ -341,6 +341,9 @@ public: void Append(TypePtr t); void AppendEvenIfNotPure(TypePtr t); + // Resets the list to be empty. + void Clear() { types.clear(); } + detail::TraversalCode Traverse(detail::TraversalCallback* cb) const override; protected: diff --git a/src/Val.h b/src/Val.h index 1267f602ec..f4e177d602 100644 --- a/src/Val.h +++ b/src/Val.h @@ -684,6 +684,15 @@ public: */ void Append(ValPtr v); + /** + * Empties the list. + * @param v the value to append. + */ + void Clear() { + vals.clear(); + type->AsTypeList()->Clear(); + } + // Returns a Set representation of the list (which must be homogeneous). TableValPtr ToSetVal() const;