diff --git a/src/Expr.cc b/src/Expr.cc index 02a6ba83a0..7b0d8e8f73 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -744,7 +744,7 @@ IntrusivePtr BinaryExpr::SetFold(Val* v1, Val* v2) const switch ( tag ) { case EXPR_AND: - return {AdoptRef{}, tv1->Intersect(tv2)}; + return tv1->Intersection(*tv2); case EXPR_OR: { diff --git a/src/Val.cc b/src/Val.cc index 88d67692e3..9e293a51b9 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1664,12 +1664,12 @@ bool TableVal::RemoveFrom(Val* val) const return true; } -TableVal* TableVal::Intersect(const TableVal* tv) const +IntrusivePtr TableVal::Intersection(const TableVal& tv) const { - TableVal* result = new TableVal(table_type); + auto result = make_intrusive(table_type); const PDict* t0 = AsTable(); - const PDict* t1 = tv->AsTable(); + const PDict* t1 = tv.AsTable(); PDict* t2 = result->AsNonConstTable(); // Figure out which is smaller; assign it to t1. diff --git a/src/Val.h b/src/Val.h index ec8fed0ef2..a552ec0e53 100644 --- a/src/Val.h +++ b/src/Val.h @@ -795,11 +795,19 @@ public: // Returns true if the addition typechecked, false if not. bool RemoveFrom(Val* v) const override; - // Returns a new table that is the intersection of this - // table and the given table. Intersection is just done - // on index, not on yield value, so this really only makes - // sense for sets. - TableVal* Intersect(const TableVal* v) const; + /** + * Returns a new table that is the intersection of this table + * and the given table. Intersection is done only on index, not on + * yield value, so this generally makes most sense to use for sets, + * not tables. + * @param v The intersecting table. + * @return The intersection of this table and the given one. + */ + IntrusivePtr Intersection(const TableVal& v) const; + + [[deprecated("Remove in v4.1. Use Intersection() instead.")]] + TableVal* Intersect(const TableVal* v) const + { return Intersection(*v).release(); } // Returns true if this set contains the same members as the // given set. Note that comparisons are done using hash keys,