Skip to content

Commit

Permalink
autovector: optimize front() and back()
Browse files Browse the repository at this point in the history
  • Loading branch information
rockeet committed Jun 25, 2022
1 parent 9d8106d commit 58d069c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions util/autovector.h
Expand Up @@ -271,22 +271,22 @@ class autovector {

reference front() {
assert(!empty());
return *begin();
return values_[0];
}

const_reference front() const {
assert(!empty());
return *begin();
return values_[0];
}

reference back() {
assert(!empty());
return *(end() - 1);
return vect_.empty() ? values_[num_stack_items_-1] : vect_.back();
}

const_reference back() const {
assert(!empty());
return *(end() - 1);
return vect_.empty() ? values_[num_stack_items_-1] : vect_.back();
}

// -- Mutable Operations
Expand Down

0 comments on commit 58d069c

Please sign in to comment.