Skip to content

Commit 496dd6b

Browse files
committed
borrow from @traversc's push_back_fast
1 parent bbee709 commit 496dd6b

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

inst/include/cpp11/strings.hpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,15 @@ inline void r_vector<r_string>::set_elt(
6767
SET_STRING_ELT(x, i, value);
6868
}
6969

70-
// Pacha: Optimized subscript assignment for std::string
71-
template <>
72-
inline typename r_vector<r_string>::proxy r_vector<r_string>::operator[](
73-
R_xlen_t i) const {
74-
return typename r_vector<r_string>::proxy(data_, i, nullptr, false);
75-
}
76-
77-
// Pacha: Optimized push_back for std::string
70+
// Pacha: Optimized push_back for std::string (borrows from @traversc' push_back_fast)
7871
template <>
7972
template <typename U, typename std::enable_if<std::is_same<U, r_string>::value>::type*>
8073
inline void r_vector<r_string>::push_back(const std::string& value) {
8174
while (this->length_ >= this->capacity_) {
8275
this->reserve(this->capacity_ == 0 ? 1 : this->capacity_ * 2);
8376
}
84-
85-
SEXP char_sexp = Rf_mkCharLenCE(value.c_str(), value.size(), CE_UTF8);
86-
SET_STRING_ELT(this->data_, this->length_, char_sexp);
77+
set_elt(this->data_, this->length_,
78+
Rf_mkCharLenCE(value.c_str(), value.size(), CE_UTF8));
8779
++this->length_;
8880
}
8981

0 commit comments

Comments
 (0)