Skip to content

Commit

Permalink
Add optimization hints to EvaluatorStack and switch some to FATAL
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 605022108
  • Loading branch information
jcking authored and copybara-github committed Feb 7, 2024
1 parent 8e6acc7 commit c930763
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions eval/eval/evaluator_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class EvaluatorStack {
// Checking that stack has enough elements is caller's responsibility.
// Please note that calls to Push may invalidate returned Span object.
absl::Span<const cel::Value> GetSpan(size_t size) const {
if (!HasEnough(size)) {
ABSL_LOG(ERROR) << "Requested span size (" << size
if (ABSL_PREDICT_FALSE(!HasEnough(size))) {
ABSL_LOG(FATAL) << "Requested span size (" << size
<< ") exceeds current stack size: " << current_size_;
}
return absl::Span<const cel::Value>(stack_.data() + current_size_ - size,
Expand All @@ -57,24 +57,37 @@ class EvaluatorStack {
// Checking that stack has enough elements is caller's responsibility.
// Please note that calls to Push may invalidate returned Span object.
absl::Span<const AttributeTrail> GetAttributeSpan(size_t size) const {
if (ABSL_PREDICT_FALSE(!HasEnough(size))) {
ABSL_LOG(FATAL) << "Requested span size (" << size
<< ") exceeds current stack size: " << current_size_;
}
return absl::Span<const AttributeTrail>(
attribute_stack_.data() + current_size_ - size, size);
}

// Peeks the last element of the stack.
// Checking that stack is not empty is caller's responsibility.
cel::Value& Peek() {
if (ABSL_PREDICT_FALSE(empty())) {
ABSL_LOG(FATAL) << "Peeking on empty EvaluatorStack";
}
return stack_[current_size_ - 1];
}

// Peeks the last element of the stack.
// Checking that stack is not empty is caller's responsibility.
const cel::Value& Peek() const {
if (empty()) {
ABSL_LOG(ERROR) << "Peeking on empty EvaluatorStack";
if (ABSL_PREDICT_FALSE(empty())) {
ABSL_LOG(FATAL) << "Peeking on empty EvaluatorStack";
}
return stack_[current_size_ - 1];
}

// Peeks the last element of the attribute stack.
// Checking that stack is not empty is caller's responsibility.
const AttributeTrail& PeekAttribute() const {
if (empty()) {
ABSL_LOG(ERROR) << "Peeking on empty EvaluatorStack";
if (ABSL_PREDICT_FALSE(empty())) {
ABSL_LOG(FATAL) << "Peeking on empty EvaluatorStack";
}
return attribute_stack_[current_size_ - 1];
}
Expand All @@ -83,7 +96,7 @@ class EvaluatorStack {
// Checking that stack has enough elements is caller's responsibility.
void Pop(size_t size) {
if (ABSL_PREDICT_FALSE(!HasEnough(size))) {
ABSL_LOG(ERROR) << "Trying to pop more elements (" << size
ABSL_LOG(FATAL) << "Trying to pop more elements (" << size
<< ") than the current stack size: " << current_size_;
}
while (size > 0) {
Expand Down

0 comments on commit c930763

Please sign in to comment.