Skip to content

Commit 849df0b

Browse files
committed
More cleanups in argument vector, per comments.
1 parent bc9c877 commit 849df0b

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

include/pybind11/detail/argument_vector.h

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -165,25 +165,23 @@ struct small_vector {
165165
return m_repr.hvector.vec[idx];
166166
}
167167

168-
void push_back(T x) {
168+
void push_back(T const &x) { emplace_back(x); }
169+
170+
template <typename... Args>
171+
void emplace_back(Args &&...x) {
169172
if (is_inline()) {
170173
auto &ha = m_repr.iarray;
171174
if (ha.size == InlineSize) {
172175
move_to_heap_vector_with_reserved_size(InlineSize + 1);
173-
push_back_slow_path(std::move(x));
176+
m_repr.hvector.vec.emplace_back(std::forward<Args>(x)...);
174177
} else {
175-
ha.arr[ha.size++] = std::move(x);
178+
ha.arr[ha.size++] = T(std::forward<Args>(x)...);
176179
}
177180
} else {
178-
push_back_slow_path(std::move(x));
181+
m_repr.hvector.vec.emplace_back(std::forward<Args>(x)...);
179182
}
180183
}
181184

182-
template <typename Arg>
183-
void emplace_back(Arg &&x) {
184-
push_back(T(x));
185-
}
186-
187185
void reserve(std::size_t sz) {
188186
if (is_inline()) {
189187
if (sz > InlineSize) {
@@ -194,19 +192,6 @@ struct small_vector {
194192
}
195193
}
196194

197-
void sort() {
198-
if (is_inline()) {
199-
if (m_repr.iarray.size < m_repr.iarray.arr.size()) {
200-
std::sort(m_repr.iarray.arr.begin(),
201-
m_repr.iarray.arr.begin() + m_repr.iarray.size);
202-
} else {
203-
std::sort(m_repr.iarray.arr.begin(), m_repr.iarray.arr.end());
204-
}
205-
} else {
206-
std::sort(m_repr.hvector.vec.begin(), m_repr.hvector.vec.end());
207-
}
208-
}
209-
210195
private:
211196
using repr_type = inline_array_or_vector<T, InlineSize>;
212197
repr_type m_repr;
@@ -225,8 +210,6 @@ struct small_vector {
225210
new (&m_repr.hvector) heap_vector(std::move(hv));
226211
}
227212

228-
PYBIND11_NOINLINE void push_back_slow_path(T x) { m_repr.hvector.vec.push_back(std::move(x)); }
229-
230213
PYBIND11_NOINLINE void reserve_slow_path(std::size_t sz) { m_repr.hvector.vec.reserve(sz); }
231214

232215
bool is_inline() const { return m_repr.is_inline(); }
@@ -303,6 +286,23 @@ struct small_vector<bool, kRequestedInlineSize> {
303286
}
304287
}
305288

289+
void set(std::size_t idx, bool value = true) {
290+
if (is_inline()) {
291+
auto &ha = m_repr.iarray;
292+
assert(ha.size < kInlineSize);
293+
const auto wbi = word_and_bit_index(idx);
294+
assert(wbi.word < kWords);
295+
assert(wbi.bit < kBitsPerWord);
296+
if (value) {
297+
ha.arr[wbi.word] |= (static_cast<std::size_t>(1) << wbi.bit);
298+
} else {
299+
ha.arr[wbi.word] &= ~(static_cast<std::size_t>(1) << wbi.bit);
300+
}
301+
} else {
302+
m_repr.hvector.vec[idx] = value;
303+
}
304+
}
305+
306306
void swap(small_vector &rhs) noexcept { std::swap(m_repr, rhs.m_repr); }
307307

308308
private:

0 commit comments

Comments
 (0)