/*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2014 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
/*
- * For high-level documentation and usage examples see folly/doc/small_vector.md
+ * For high-level documentation and usage examples see
+ * folly/docs/small_vector.md
*
* @author Jordan DeLong <delong.j@fb.com>
*/
#include "folly/Malloc.h"
-#if defined(__GNUC__) && defined(__x86_64__)
+#if defined(__GNUC__) && FOLLY_X64
# include "folly/SmallLocks.h"
# define FB_PACKED __attribute__((packed))
#else
# define FB_PACKED
#endif
-#ifdef FOLLY_HAVE_MALLOC_SIZE
+#if FOLLY_HAVE_MALLOC_SIZE
extern "C" std::size_t malloc_size(const void*);
-# ifndef FOLLY_HAVE_MALLOC_USABLE_SIZE
+# if !FOLLY_HAVE_MALLOC_USABLE_SIZE
# define malloc_usable_size malloc_size
# endif
# ifndef malloc_usable_size
# endif
#endif
+// Ignore shadowing warnings within this file, so includers can use -Wshadow.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wshadow"
+
namespace folly {
//////////////////////////////////////////////////////////////////////
*/
template<class T>
typename std::enable_if<
- !boost::has_trivial_copy<T>::value
+ !FOLLY_IS_TRIVIALLY_COPYABLE(T)
>::type
moveToUninitialized(T* first, T* last, T* out) {
auto const count = last - first;
}
}
- // Specialization for trivially copyable types. (TODO: change to
- // std::is_trivially_copyable when that works.)
+ // Specialization for trivially copyable types.
template<class T>
typename std::enable_if<
- boost::has_trivial_copy<T>::value
+ FOLLY_IS_TRIVIALLY_COPYABLE(T)
>::type
moveToUninitialized(T* first, T* last, T* out) {
std::memmove(out, first, (last - first) * sizeof *first);
*/
template<class T>
typename std::enable_if<
- !boost::has_trivial_copy<T>::value
+ !FOLLY_IS_TRIVIALLY_COPYABLE(T)
>::type
moveObjectsRight(T* first, T* lastConstructed, T* realLast) {
if (lastConstructed == realLast) {
// change to std::is_trivially_copyable when that works.)
template<class T>
typename std::enable_if<
- boost::has_trivial_copy<T>::value
+ FOLLY_IS_TRIVIALLY_COPYABLE(T)
>::type
moveObjectsRight(T* first, T* lastConstructed, T* realLast) {
std::move_backward(first, lastConstructed, realLast);
IntegralSizePolicy() : size_(0) {}
protected:
- std::size_t policyMaxSize() const {
+ static constexpr std::size_t policyMaxSize() {
return SizeType(~kExternMask);
}
SizeType size_;
};
-#ifdef __x86_64__
+#if FOLLY_X64
template<class SizeType, bool ShouldUseHeap>
struct OneBitMutexImpl {
typedef SizeType InternalSizeType;
protected:
static bool const kShouldUseHeap = ShouldUseHeap;
- std::size_t policyMaxSize() const {
+ static constexpr std::size_t policyMaxSize() {
return SizeType(~(SizeType(1) << kLockBit | kExternMask));
}
return std::lexicographical_compare(begin(), end(), o.begin(), o.end());
}
- size_type max_size() const {
+ static constexpr size_type max_size() {
return !BaseType::kShouldUseHeap ? MaxInline
- : this->policyMaxSize();
+ : BaseType::policyMaxSize();
}
size_type size() const { return this->doSize(); }
doConstruct(n, val);
}
- void makeSize(size_type size, value_type* v = NULL) {
+ void makeSize(size_type size, value_type* v = nullptr) {
makeSize(size, v, size - 1);
}
detail::shiftPointer(newh, kHeapifyCapacitySize) :
newh);
- if (v != NULL) {
+ if (v != nullptr) {
// move new element
try {
new (&newp[pos]) value_type(std::move(*v));
}
} FB_PACKED;
-#if defined(__x86_64_)
+#if FOLLY_X64
typedef unsigned char InlineStorageType[sizeof(value_type) * MaxInline];
#else
typedef typename std::aligned_storage<
}
+#pragma GCC diagnostic pop
+
#ifdef FB_PACKED
# undef FB_PACKED
#endif