Skip to content

Commit 934e16b

Browse files
committed
Update: minor enhancement
1 parent 667bd9f commit 934e16b

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

src/iceberg/expression/expression.cc

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,43 @@ bool OrImpl::Equals(const Expression& expr) const {
227227
}
228228

229229
// Implementation of Predicate static factory methods
230-
std::shared_ptr<Predicate> Predicate::AlwaysTrue() { return True::Instance(); }
230+
const std::shared_ptr<Predicate>& Predicate::AlwaysTrue() {
231+
static const std::shared_ptr<Predicate> instance = True::Instance();
232+
return instance;
233+
}
231234

232-
std::shared_ptr<Predicate> Predicate::AlwaysFalse() { return False::Instance(); }
235+
const std::shared_ptr<Predicate>& Predicate::AlwaysFalse() {
236+
static const std::shared_ptr<Predicate> instance = False::Instance();
237+
return instance;
238+
}
233239

234240
std::shared_ptr<Predicate> Predicate::And(std::shared_ptr<Predicate> left,
235241
std::shared_ptr<Predicate> right) {
242+
/*
243+
auto left_op = left->op();
244+
auto right_op = right->op();
245+
if (left_op == Operation::kFalse || right_op == Operation::kFalse) {
246+
return False::Instance();
247+
}
248+
if (left_op == Operation::kTrue && right_op == Operation::kTrue) {
249+
return left;
250+
}
251+
*/
236252
return std::make_shared<AndImpl>(std::move(left), std::move(right));
237253
}
238254

239255
std::shared_ptr<Predicate> Predicate::Or(std::shared_ptr<Predicate> left,
240256
std::shared_ptr<Predicate> right) {
257+
/*
258+
auto left_op = left->op();
259+
auto right_op = right->op();
260+
if (left_op == Operation::kTrue || right_op == Operation::kTrue) {
261+
return False::Instance();
262+
}
263+
if (left_op == Operation::kFalse && right_op == Operation::kFalse) {
264+
return left;
265+
}
266+
*/
241267
return std::make_shared<OrImpl>(std::move(left), std::move(right));
242268
}
243269

src/iceberg/expression/expression.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ class ICEBERG_EXPORT Predicate : public Expression {
127127

128128
/// \brief Creates a True predicate that always evaluates to true.
129129
/// \return A shared pointer to a True predicate
130-
static std::shared_ptr<Predicate> AlwaysTrue();
130+
static const std::shared_ptr<Predicate>& AlwaysTrue();
131131

132132
/// \brief Creates a False predicate that always evaluates to false.
133133
/// \return A shared pointer to a False predicate
134-
static std::shared_ptr<Predicate> AlwaysFalse();
134+
static const std::shared_ptr<Predicate>& AlwaysFalse();
135135

136136
/// \brief Creates an And predicate that represents logical AND of two predicates.
137137
/// \param left The left operand of the AND predicate
@@ -162,10 +162,6 @@ class ICEBERG_EXPORT BoundExpression {
162162
virtual std::string ToString() const = 0;
163163
};
164164

165-
class ICEBERG_EXPORT BoundPredicate : public BoundExpression {
166-
public:
167-
/// \brief Returns a negated version of this bound predicate.
168-
virtual std::shared_ptr<BoundPredicate> Negate() const = 0;
169-
};
165+
class ICEBERG_EXPORT BoundPredicate : public BoundExpression {};
170166

171167
} // namespace iceberg

0 commit comments

Comments
 (0)