Skip to content

Commit 1ccb711

Browse files
markchandlera-maurice
authored andcommitted
Firebase cpp: Added noexcept to ensure STL will use move constructor for containers
PiperOrigin-RevId: 277341338
1 parent 42ce22f commit 1ccb711

File tree

10 files changed

+20
-19
lines changed

10 files changed

+20
-19
lines changed

app/rest/controller_curl.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ ControllerCurl::~ControllerCurl() {
4545
}
4646

4747
#if defined(FIREBASE_USE_MOVE_OPERATORS) || defined(DOXYGEN)
48-
ControllerCurl::ControllerCurl(ControllerCurl&& other) {
48+
ControllerCurl::ControllerCurl(ControllerCurl&& other) noexcept {
4949
*this = std::move(other);
5050
}
5151

52-
ControllerCurl& ControllerCurl::operator=(ControllerCurl&& other) {
52+
ControllerCurl& ControllerCurl::operator=(ControllerCurl&& other) noexcept {
5353
direction_ = other.direction_;
5454
transport_ = other.transport_;
5555
is_paused_ = other.is_paused_;

app/rest/controller_curl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ class ControllerCurl : public Controller {
5454
~ControllerCurl() override;
5555

5656
#if defined(FIREBASE_USE_MOVE_OPERATORS) || defined(DOXYGEN)
57-
ControllerCurl(ControllerCurl&& other);
57+
ControllerCurl(ControllerCurl&& other) noexcept;
5858

59-
ControllerCurl& operator=(ControllerCurl&& other);
59+
ControllerCurl& operator=(ControllerCurl&& other) noexcept;
6060
#endif // defined(FIREBASE_USE_MOVE_OPERATORS) || defined(DOXYGEN)
6161

6262
// Pauses whatever the handle is doing.

app/src/include/firebase/future.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ class FutureBase {
117117
/// Move constructor and operator.
118118
/// Move is more efficient than copy and delete because we don't touch the
119119
/// reference counting in the API.
120-
FutureBase(FutureBase&& rhs);
120+
FutureBase(FutureBase&& rhs) noexcept;
121121

122122
/// Copy an untyped future.
123-
FutureBase& operator=(FutureBase&& rhs);
123+
FutureBase& operator=(FutureBase&& rhs) noexcept;
124124
#endif // defined(FIREBASE_USE_MOVE_OPERATORS)
125125

126126
/// Explicitly release the internal resources for a future.

app/src/include/firebase/internal/future_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,15 @@ inline FutureBase& FutureBase::operator=(const FutureBase& rhs) {
231231
}
232232

233233
#if defined(FIREBASE_USE_MOVE_OPERATORS)
234-
inline FutureBase::FutureBase(FutureBase&& rhs)
234+
inline FutureBase::FutureBase(FutureBase&& rhs) noexcept
235235
: api_(NULL) // NOLINT
236236
{
237237
detail::UnregisterForCleanup(rhs.api_, &rhs);
238238
*this = std::move(rhs);
239239
detail::RegisterForCleanup(api_, this);
240240
}
241241

242-
inline FutureBase& FutureBase::operator=(FutureBase&& rhs) {
242+
inline FutureBase& FutureBase::operator=(FutureBase&& rhs) noexcept {
243243
Release();
244244
detail::UnregisterForCleanup(rhs.api_, &rhs);
245245
api_ = rhs.api_;

app/src/include/firebase/variant.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,15 @@ class Variant {
240240
/// simply reassigning pointer ownership.
241241
///
242242
/// @param[in] other Source Variant to move from.
243-
Variant(Variant&& other) : type_(kInternalTypeNull) {
243+
Variant(Variant&& other) noexcept : type_(kInternalTypeNull) {
244244
*this = std::move(other);
245245
}
246246

247247
/// @brief Move assignment operator. Efficiently moves the more complex data
248248
/// types by simply reassigning pointer ownership.
249249
///
250250
/// @param[in] other Source Variant to move from.
251-
Variant& operator=(Variant&& other);
251+
Variant& operator=(Variant&& other) noexcept;
252252

253253
#endif // defined(FIREBASE_USE_MOVE_OPERATORS) || defined(DOXYGEN)
254254
#endif // SWIG

app/src/intrusive_list.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@ class intrusive_list {
251251
: data_(&data_, &data_), node_offset_(offset_of_node(node_member)) {}
252252

253253
#if defined(FIREBASE_USE_MOVE_OPERATORS)
254-
intrusive_list(this_type&& other) { *this = std::move(other); }
254+
intrusive_list(this_type&& other) noexcept { *this = std::move(other); }
255255

256-
intrusive_list& operator=(this_type&& other) {
256+
intrusive_list& operator=(this_type&& other) noexcept {
257257
data_ = std::move(other.data_);
258258
node_offset_ = std::move(other.node_offset_);
259259
return *this;

app/src/jobject_reference.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ JObjectReference::JObjectReference(const JObjectReference& reference) {
3939
}
4040

4141
#ifdef FIREBASE_USE_MOVE_OPERATORS
42-
JObjectReference::JObjectReference(JObjectReference&& reference) {
42+
JObjectReference::JObjectReference(JObjectReference&& reference) noexcept {
4343
operator=(std::move(reference));
4444
}
4545
#endif // FIREBASE_USE_MOVE_OPERATORS
@@ -53,7 +53,8 @@ JObjectReference& JObjectReference::operator=(
5353
}
5454

5555
#ifdef FIREBASE_USE_MOVE_OPERATORS
56-
JObjectReference& JObjectReference::operator=(JObjectReference&& reference) {
56+
JObjectReference& JObjectReference::operator=(JObjectReference&& reference)
57+
noexcept {
5758
java_vm_ = reference.java_vm_;
5859
object_ = reference.object_;
5960
reference.java_vm_ = nullptr;

app/src/jobject_reference.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ class JObjectReference {
6666
JObjectReference(const JObjectReference& reference);
6767
// Move
6868
#ifdef FIREBASE_USE_MOVE_OPERATORS
69-
JObjectReference(JObjectReference&& reference);
69+
JObjectReference(JObjectReference&& reference) noexcept;
7070
#endif // FIREBASE_USE_MOVE_OPERATORS
7171
// Delete the reference to the java object.
7272
~JObjectReference();
7373
// Copy this reference.
7474
JObjectReference& operator=(const JObjectReference& reference);
7575
// Move this reference.
7676
#ifdef FIREBASE_USE_MOVE_OPERATORS
77-
JObjectReference& operator=(JObjectReference&& reference);
77+
JObjectReference& operator=(JObjectReference&& reference) noexcept;
7878
#endif // FIREBASE_USE_MOVE_OPERATORS
7979

8080
// Add a global reference to the specified object, removing the reference

app/src/optional.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Optional {
6969
#if defined(FIREBASE_USE_MOVE_OPERATORS)
7070
// Move contructor. If the other Optional has a value, it is moved into this
7171
// Optional using its move constructor.
72-
Optional(Optional&& other) : has_value_(other.has_value_) {
72+
Optional(Optional&& other) noexcept : has_value_(other.has_value_) {
7373
if (has_value()) {
7474
new (aligned_buffer()) value_type(std::move(other.value()));
7575
other.reset();
@@ -78,7 +78,7 @@ class Optional {
7878

7979
// Move assignment. If the other Optional has a value, it is move constructed
8080
// or move assigned into this Optional.
81-
Optional& operator=(Optional&& other) {
81+
Optional& operator=(Optional&& other) noexcept {
8282
if (other.has_value()) {
8383
*this = std::move(other.value());
8484
} else {

app/src/variant.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Variant& Variant::operator=(const Variant& other) {
8686

8787
#if defined(FIREBASE_USE_MOVE_OPERATORS)
8888

89-
Variant& Variant::operator=(Variant&& other) {
89+
Variant& Variant::operator=(Variant&& other) noexcept {
9090
if (this != &other) {
9191
Clear();
9292
type_ = other.type_;

0 commit comments

Comments
 (0)