From 8ab8e40d15a4d9f28ced76d28232f9e791f161d3 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 28 Oct 2022 12:15:53 -0700 Subject: [NFC] Rewrite PossibleContents::combine to be static (#5192) This makes the logic symmetric and easier to read. Measuring speed, this seems identical to before, so that concern seems fine. --- src/ir/possible-contents.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/ir/possible-contents.h') diff --git a/src/ir/possible-contents.h b/src/ir/possible-contents.h index cf92a578a..b7c9bfafd 100644 --- a/src/ir/possible-contents.h +++ b/src/ir/possible-contents.h @@ -103,12 +103,12 @@ class PossibleContents { // full cone of all subtypes for that type. static ConeType FullConeType(Type type) { return ConeType{type, FullDepth}; } + template PossibleContents(T value) : value(value) {} + public: PossibleContents() : value(None()) {} PossibleContents(const PossibleContents& other) = default; - template explicit PossibleContents(T val) : value(val) {} - // Most users will use one of the following static functions to construct a // new instance: @@ -163,7 +163,12 @@ public: // Combine the information in a given PossibleContents to this one. The // contents here will then include whatever content was possible in |other|. - void combine(const PossibleContents& other); + [[nodiscard]] static PossibleContents combine(const PossibleContents& a, + const PossibleContents& b); + + void combine(const PossibleContents& other) { + *this = PossibleContents::combine(*this, other); + } // Removes anything not in |other| from this object, so that it ends up with // only their intersection. Currently this only handles an intersection with a -- cgit v1.2.3