Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<deque>: many internal operations could use unchecked iterators #2868

Closed
CaseyCarter opened this issue Jul 16, 2022 · 0 comments · Fixed by #4071
Closed

<deque>: many internal operations could use unchecked iterators #2868

CaseyCarter opened this issue Jul 16, 2022 · 0 comments · Fixed by #4071
Labels
fixed Something works now, yay! performance Must go faster

Comments

@CaseyCarter
Copy link
Contributor

deque is inconsistent about using checked vs. unchecked iterators for internal operations where checking is not needed. emplace, for example:

STL/stl/inc/deque

Lines 819 to 835 in ef62d3f

template <class... _Valty>
iterator emplace(const_iterator _Where, _Valty&&... _Val) {
const auto _Off = static_cast<size_type>(_Where - begin());
#if _ITERATOR_DEBUG_LEVEL == 2
_STL_VERIFY(_Off <= _Mysize(), "deque emplace iterator outside range");
#endif // _ITERATOR_DEBUG_LEVEL == 2
if (_Off <= _Mysize() / 2) { // closer to front, push to front then rotate
emplace_front(_STD forward<_Valty>(_Val)...);
_STD rotate(begin(), _Next_iter(begin()), begin() + static_cast<difference_type>(1 + _Off));
} else { // closer to back, push to back then rotate
emplace_back(_STD forward<_Valty>(_Val)...);
_STD rotate(begin() + static_cast<difference_type>(_Off), _Prev_iter(end()), end());
}
return begin() + static_cast<difference_type>(_Off);
}

passes checked iterators to rotate which could as well be unchecked - we know that the ranges we're forming are valid. We need to audit the file for such occurrences and change them to use unchecked iterators (returned from _Unchecked_begin and _Unchecked_end) where possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed Something works now, yay! performance Must go faster
Projects
None yet
2 participants