Skip to content

Commit

Permalink
Unify const_iterator::operator*()
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisVaughan committed Aug 9, 2024
1 parent c54765c commit f6e212f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
5 changes: 0 additions & 5 deletions inst/include/cpp11/list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ inline bool r_vector<SEXP>::const_iterator::use_buf(bool is_altrep) {
return false;
}

template <>
inline SEXP r_vector<SEXP>::const_iterator::operator*() const {
return VECTOR_ELT(data_->data(), pos_);
}

typedef r_vector<SEXP> list;

namespace writable {
Expand Down
6 changes: 4 additions & 2 deletions inst/include/cpp11/r_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,12 @@ inline typename r_vector<T>::const_iterator r_vector<T>::find(

template <typename T>
inline T r_vector<T>::const_iterator::operator*() const {
if (data_->is_altrep()) {
if (use_buf(data_->is_altrep())) {
// Use pre-loaded buffer for compatible ALTREP types
return static_cast<T>(buf_[pos_ - block_start_]);
} else {
return static_cast<T>(data_->data_p_[pos_]);
// Otherwise pass through to normal retrieval method
return data_->operator[](pos_);
}
}

Expand Down
5 changes: 0 additions & 5 deletions inst/include/cpp11/strings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ inline bool r_vector<r_string>::const_iterator::use_buf(bool is_altrep) {
return false;
}

template <>
inline r_string r_vector<r_string>::const_iterator::operator*() const {
return STRING_ELT(data_->data(), pos_);
}

typedef r_vector<r_string> strings;

namespace writable {
Expand Down

0 comments on commit f6e212f

Please sign in to comment.