Commit ba88b3f6 authored by Nicholas Ormrod's avatar Nicholas Ormrod Committed by Pavlo Kushnir

Make dynamic noexcept

Summary:
Many dynamic operations, including its move constructor, are
noexcept but not labeled so. Labeled some important functions as
noexcept.

Test Plan: run unit tests

Reviewed By: delong.j@fb.com

Subscribers: tudorb, philipp, sdwilsh, njormrod, folly-diffs@

FB internal diff: D1644380

Tasks: 5486739

Signature: t1:1644380:1414618757:fb910d8a3fe3e634da4215c432577edf7371be61
parent 3d420c10
...@@ -309,13 +309,13 @@ inline dynamic::dynamic(dynamic const& o) ...@@ -309,13 +309,13 @@ inline dynamic::dynamic(dynamic const& o)
*this = o; *this = o;
} }
inline dynamic::dynamic(dynamic&& o) inline dynamic::dynamic(dynamic&& o) noexcept
: type_(NULLT) : type_(NULLT)
{ {
*this = std::move(o); *this = std::move(o);
} }
inline dynamic::~dynamic() { destroy(); } inline dynamic::~dynamic() noexcept { destroy(); }
template<class T> template<class T>
dynamic::dynamic(T t) { dynamic::dynamic(T t) {
...@@ -508,7 +508,7 @@ inline dynamic& dynamic::operator=(dynamic const& o) { ...@@ -508,7 +508,7 @@ inline dynamic& dynamic::operator=(dynamic const& o) {
return *this; return *this;
} }
inline dynamic& dynamic::operator=(dynamic&& o) { inline dynamic& dynamic::operator=(dynamic&& o) noexcept {
if (&o != this) { if (&o != this) {
destroy(); destroy();
#define FB_X(T) new (getAddress<T>()) T(std::move(*o.getAddress<T>())) #define FB_X(T) new (getAddress<T>()) T(std::move(*o.getAddress<T>()))
...@@ -772,7 +772,7 @@ T dynamic::asImpl() const { ...@@ -772,7 +772,7 @@ T dynamic::asImpl() const {
// Return a T* to our type, or null if we're not that type. // Return a T* to our type, or null if we're not that type.
template<class T> template<class T>
T* dynamic::get_nothrow() { T* dynamic::get_nothrow() noexcept {
if (type_ != TypeInfo<T>::type) { if (type_ != TypeInfo<T>::type) {
return nullptr; return nullptr;
} }
...@@ -780,40 +780,40 @@ T* dynamic::get_nothrow() { ...@@ -780,40 +780,40 @@ T* dynamic::get_nothrow() {
} }
template<class T> template<class T>
T const* dynamic::get_nothrow() const { T const* dynamic::get_nothrow() const noexcept {
return const_cast<dynamic*>(this)->get_nothrow<T>(); return const_cast<dynamic*>(this)->get_nothrow<T>();
} }
// Return T* for where we can put a T, without type checking. (Memory // Return T* for where we can put a T, without type checking. (Memory
// might be uninitialized, even.) // might be uninitialized, even.)
template<class T> template<class T>
T* dynamic::getAddress() { T* dynamic::getAddress() noexcept {
return GetAddrImpl<T>::get(u_); return GetAddrImpl<T>::get(u_);
} }
template<class T> template<class T>
T const* dynamic::getAddress() const { T const* dynamic::getAddress() const noexcept {
return const_cast<dynamic*>(this)->getAddress<T>(); return const_cast<dynamic*>(this)->getAddress<T>();
} }
template<class T> struct dynamic::GetAddrImpl {}; template<class T> struct dynamic::GetAddrImpl {};
template<> struct dynamic::GetAddrImpl<void*> { template<> struct dynamic::GetAddrImpl<void*> {
static void** get(Data& d) { return &d.nul; } static void** get(Data& d) noexcept { return &d.nul; }
}; };
template<> struct dynamic::GetAddrImpl<dynamic::Array> { template<> struct dynamic::GetAddrImpl<dynamic::Array> {
static Array* get(Data& d) { return &d.array; } static Array* get(Data& d) noexcept { return &d.array; }
}; };
template<> struct dynamic::GetAddrImpl<bool> { template<> struct dynamic::GetAddrImpl<bool> {
static bool* get(Data& d) { return &d.boolean; } static bool* get(Data& d) noexcept { return &d.boolean; }
}; };
template<> struct dynamic::GetAddrImpl<int64_t> { template<> struct dynamic::GetAddrImpl<int64_t> {
static int64_t* get(Data& d) { return &d.integer; } static int64_t* get(Data& d) noexcept { return &d.integer; }
}; };
template<> struct dynamic::GetAddrImpl<double> { template<> struct dynamic::GetAddrImpl<double> {
static double* get(Data& d) { return &d.doubl; } static double* get(Data& d) noexcept { return &d.doubl; }
}; };
template<> struct dynamic::GetAddrImpl<fbstring> { template<> struct dynamic::GetAddrImpl<fbstring> {
static fbstring* get(Data& d) { return &d.string; } static fbstring* get(Data& d) noexcept { return &d.string; }
}; };
template<> struct dynamic::GetAddrImpl<dynamic::ObjectImpl> { template<> struct dynamic::GetAddrImpl<dynamic::ObjectImpl> {
static_assert(sizeof(ObjectImpl) <= sizeof(Data::objectBuffer), static_assert(sizeof(ObjectImpl) <= sizeof(Data::objectBuffer),
...@@ -821,7 +821,7 @@ template<> struct dynamic::GetAddrImpl<dynamic::ObjectImpl> { ...@@ -821,7 +821,7 @@ template<> struct dynamic::GetAddrImpl<dynamic::ObjectImpl> {
" amount of space depending on its template parameters. This is " " amount of space depending on its template parameters. This is "
"weird. Make objectBuffer bigger if you want to compile dynamic."); "weird. Make objectBuffer bigger if you want to compile dynamic.");
static ObjectImpl* get(Data& d) { static ObjectImpl* get(Data& d) noexcept {
void* data = &d.objectBuffer; void* data = &d.objectBuffer;
return static_cast<ObjectImpl*>(data); return static_cast<ObjectImpl*>(data);
} }
...@@ -846,7 +846,7 @@ inline char const* dynamic::typeName(Type t) { ...@@ -846,7 +846,7 @@ inline char const* dynamic::typeName(Type t) {
#undef FB_X #undef FB_X
} }
inline void dynamic::destroy() { inline void dynamic::destroy() noexcept {
// This short-circuit speeds up some microbenchmarks. // This short-circuit speeds up some microbenchmarks.
if (type_ == NULLT) return; if (type_ == NULLT) return;
......
...@@ -180,8 +180,8 @@ public: ...@@ -180,8 +180,8 @@ public:
template<class Iterator> dynamic(Iterator first, Iterator last); template<class Iterator> dynamic(Iterator first, Iterator last);
dynamic(dynamic const&); dynamic(dynamic const&);
dynamic(dynamic&&); dynamic(dynamic&&) noexcept;
~dynamic(); ~dynamic() noexcept;
/* /*
* "Deep" equality comparison. This will compare all the way down * "Deep" equality comparison. This will compare all the way down
...@@ -223,7 +223,7 @@ public: ...@@ -223,7 +223,7 @@ public:
* Basic guarantee only. * Basic guarantee only.
*/ */
dynamic& operator=(dynamic const&); dynamic& operator=(dynamic const&);
dynamic& operator=(dynamic&&); dynamic& operator=(dynamic&&) noexcept;
/* /*
* For simple dynamics (not arrays or objects), this prints the * For simple dynamics (not arrays or objects), this prints the
...@@ -494,15 +494,15 @@ private: ...@@ -494,15 +494,15 @@ private:
template<class T> T const& get() const; template<class T> T const& get() const;
template<class T> T& get(); template<class T> T& get();
template<class T> T* get_nothrow(); template<class T> T* get_nothrow() noexcept;
template<class T> T const* get_nothrow() const; template<class T> T const* get_nothrow() const noexcept;
template<class T> T* getAddress(); template<class T> T* getAddress() noexcept;
template<class T> T const* getAddress() const; template<class T> T const* getAddress() const noexcept;
template<class T> T asImpl() const; template<class T> T asImpl() const;
static char const* typeName(Type); static char const* typeName(Type);
void destroy(); void destroy() noexcept;
void print(std::ostream&) const; void print(std::ostream&) const;
void print_as_pseudo_json(std::ostream&) const; // see json.cpp void print_as_pseudo_json(std::ostream&) const; // see json.cpp
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment