20 #include <type_traits> 32 struct FollyMemoryDetailTranslationUnitTag {};
92 if (n > s.capacity()) {
122 typename =
typename std::enable_if<
129 if (n > v.capacity()) {
138 #if defined(_LIBCPP_STRING) 143 template void std::string::__set_size(std::size_t);
147 template <
typename Tag,
typename T,
typename A, A Ptr__set_size>
148 struct MakeUnsafeStringSetLargerSize {
150 std::basic_string<T>&
s,
153 (s.*Ptr__set_size)(n);
157 template struct MakeUnsafeStringSetLargerSize<
158 FollyMemoryDetailTranslationUnitTag,
161 &std::string::__set_size>;
163 #elif defined(_GLIBCXX_USE_FB) 166 template <
typename Tag,
typename T,
typename A, A Ptrstore_>
167 struct MakeUnsafeStringSetLargerSize {
169 std::basic_string<T>&
s,
172 (s.*Ptrstore_).expandNoinit(n - s.size(),
false);
175 template struct MakeUnsafeStringSetLargerSize<
176 FollyMemoryDetailTranslationUnitTag,
179 &std::string::store_>;
181 #elif defined(_GLIBCXX_STRING) && _GLIBCXX_USE_CXX11_ABI 186 template void std::string::_M_set_length(std::size_t);
190 template <
typename Tag,
typename T,
typename A, A Ptr_M_set_length>
191 struct MakeUnsafeStringSetLargerSize {
193 std::basic_string<T>&
s,
196 (s.*Ptr_M_set_length)(n);
199 template struct MakeUnsafeStringSetLargerSize<
200 FollyMemoryDetailTranslationUnitTag,
203 &std::string::_M_set_length>;
205 #elif defined(_GLIBCXX_STRING) 210 template std::string::_Rep* std::string::_M_rep()
const;
211 template void std::string::_Rep::_M_set_length_and_sharable(std::size_t);
221 B Ptr_M_set_length_and_sharable>
222 struct MakeUnsafeStringSetLargerSize {
224 std::basic_string<T>&
s,
227 auto rep = (s.*Ptr_M_rep)();
228 (rep->*Ptr_M_set_length_and_sharable)(n);
231 template struct MakeUnsafeStringSetLargerSize<
232 FollyMemoryDetailTranslationUnitTag,
235 &std::string::_M_rep,
236 void (std::string::_Rep::*)(std::size_t),
237 &std::string::_Rep::_M_set_length_and_sharable>;
239 #elif defined(_MSC_VER) 247 #warning "No implementation for resizeWithoutInitialization of std::string" 251 #define FOLLY_DECLARE_VECTOR_RESIZE_WITHOUT_INIT_IMPL(TYPE) \ 254 void unsafeVectorSetLargerSizeImpl(std::vector<TYPE>& v, std::size_t); \ 256 inline void unsafeVectorSetLargerSize<TYPE>( \ 257 std::vector<TYPE> & v, \ 259 unsafeVectorSetLargerSizeImpl(v, n); \ 264 #if defined(_LIBCPP_VECTOR) 267 template <
typename Tag,
typename T,
typename A, A Ptr__end_>
268 struct MakeUnsafeVectorSetLargerSize {
269 friend void unsafeVectorSetLargerSizeImpl(std::vector<T>&
v, std::size_t n) {
271 using Base = std::__vector_base<T, std::allocator<T>>;
273 std::is_standard_layout<std::vector<T>>::
value &&
274 sizeof(std::vector<T>) ==
sizeof(
Base),
275 "reinterpret_cast safety conditions not met");
276 reinterpret_cast<Base&
>(
v).*Ptr__end_ += (n - v.size());
280 #define FOLLY_DECLARE_VECTOR_RESIZE_WITHOUT_INIT(TYPE) \ 281 template struct folly::detail::MakeUnsafeVectorSetLargerSize< \ 282 FollyMemoryDetailTranslationUnitTag, \ 284 TYPE*(std::__vector_base<TYPE, std::allocator<TYPE>>::*), \ 285 &std::vector<TYPE>::__end_>; \ 286 FOLLY_DECLARE_VECTOR_RESIZE_WITHOUT_INIT_IMPL(TYPE) 288 #elif defined(_GLIBCXX_VECTOR) 298 struct MakeUnsafeVectorSetLargerSize : std::vector<T> {
299 friend void unsafeVectorSetLargerSizeImpl(std::vector<T>&
v, std::size_t n) {
301 (v.*Ptr_M_impl).*Ptr_M_finish += (n - v.size());
305 #define FOLLY_DECLARE_VECTOR_RESIZE_WITHOUT_INIT(TYPE) \ 306 template struct folly::detail::MakeUnsafeVectorSetLargerSize< \ 307 FollyMemoryDetailTranslationUnitTag, \ 309 std::vector<TYPE>::_Vector_impl( \ 310 std::_Vector_base<TYPE, std::allocator<TYPE>>::*), \ 311 &std::vector<TYPE>::_M_impl, \ 312 TYPE*(std::vector<TYPE>::_Vector_impl::*), \ 313 &std::vector<TYPE>::_Vector_impl::_M_finish>; \ 314 FOLLY_DECLARE_VECTOR_RESIZE_WITHOUT_INIT_IMPL(TYPE) 316 #elif defined(_MSC_VER) 319 #define FOLLY_DECLARE_VECTOR_RESIZE_WITHOUT_INIT(TYPE) \ 320 extern inline void unsafeVectorSetLargerSizeImpl( \ 321 std::vector<TYPE>& v, std::size_t n) { \ 322 v._Mylast() += (n - v.size()); \ 324 FOLLY_DECLARE_VECTOR_RESIZE_WITHOUT_INIT_IMPL(TYPE) 327 #warning "No implementation for resizeWithoutInitialization of std::vector" 333 #if defined(FOLLY_DECLARE_VECTOR_RESIZE_WITHOUT_INIT) 334 FOLLY_DECLARE_VECTOR_RESIZE_WITHOUT_INIT(
char)
335 FOLLY_DECLARE_VECTOR_RESIZE_WITHOUT_INIT(
unsigned char)
void unsafeStringSetLargerSize(std::string &s, std::size_t n)
—— Concurrent Priority Queue Implementation ——
void unsafeVectorSetLargerSize(std::vector< T > &v, std::size_t n)
void resizeWithoutInitialization(std::vector< T > &v, std::size_t n)
AtomicCounter< T, DeterministicAtomic > Base
static const char *const value