Remove scoped_generic::swap()
The main selling point of swap() in a C++11 (and up) world is
exception safety, and we don't use exceptions. So
foo.swap(bar);
can be replaced with
if (foo.get() != bar.get())
foo = std::move(bar)
in the five places where we call this function.
This allows removing the expensive <algorithm> include
in scoped_generic.h.
No behavior change.
Bug: 242216
Change-Id: I3aeb021f8715fd32574ea6843f70fe39bd8364fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3535583
Auto-Submit: Nico Weber <[email protected]>
Commit-Queue: Nico Weber <[email protected]>
Reviewed-by: Robert Sesek <[email protected]>
Commit-Queue: Robert Sesek <[email protected]>
Cr-Commit-Position: refs/heads/main@{#983351}
diff --git a/base/scoped_generic.h b/base/scoped_generic.h
index 0e705670..b9cfaf5 100644
--- a/base/scoped_generic.h
+++ b/base/scoped_generic.h
@@ -7,8 +7,7 @@
#include <stdlib.h>
-#include <algorithm>
-#include <utility>
+#include <type_traits>
#include "base/check.h"
#include "base/memory/raw_ptr.h"
@@ -143,25 +142,6 @@
TrackAcquire(value);
}
- void swap(ScopedGeneric& other) {
- if (&other == this) {
- return;
- }
-
- TrackRelease(data_.generic);
- other.TrackRelease(other.data_.generic);
-
- // Standard swap idiom: 'using std::swap' ensures that std::swap is
- // present in the overload set, but we call swap unqualified so that
- // any more-specific overloads can be used, if available.
- using std::swap;
- swap(static_cast<Traits&>(data_), static_cast<Traits&>(other.data_));
- swap(data_.generic, other.data_.generic);
-
- TrackAcquire(data_.generic);
- other.TrackAcquire(other.data_.generic);
- }
-
// Release the object. The return value is the current object held by this
// object. After this operation, this object will hold a null value, and
// will not own the object any more.