Use std::tie() for operator< in content/
Simplify the code for operator< when comparing multiple members using
a common std::tie idiom.
BUG=555171
[email protected]
Review URL: https://codereview.chromium.org/1462213002
Cr-Commit-Position: refs/heads/master@{#360883}
diff --git a/content/browser/host_zoom_map_impl.h b/content/browser/host_zoom_map_impl.h
index a9b2a45..dbf166a 100644
--- a/content/browser/host_zoom_map_impl.h
+++ b/content/browser/host_zoom_map_impl.h
@@ -7,6 +7,7 @@
#include <map>
#include <string>
+#include <tuple>
#include <vector>
#include "base/compiler_specific.h"
@@ -112,9 +113,8 @@
: render_process_id(render_process_id),
render_view_id(render_view_id) {}
bool operator<(const RenderViewKey& other) const {
- return render_process_id < other.render_process_id ||
- ((render_process_id == other.render_process_id) &&
- (render_view_id < other.render_view_id));
+ return std::tie(render_process_id, render_view_id) <
+ std::tie(other.render_process_id, other.render_view_id);
}
};
diff --git a/content/browser/loader/global_routing_id.h b/content/browser/loader/global_routing_id.h
index a15e93d..df5f202 100644
--- a/content/browser/loader/global_routing_id.h
+++ b/content/browser/loader/global_routing_id.h
@@ -5,6 +5,8 @@
#ifndef CONTENT_BROWSER_LOADER_GLOBAL_ROUTING_ID_H_
#define CONTENT_BROWSER_LOADER_GLOBAL_ROUTING_ID_H_
+#include <tuple>
+
namespace content {
// Uniquely identifies the route from which a net::URLRequest comes.
@@ -24,9 +26,8 @@
int route_id;
bool operator<(const GlobalRoutingID& other) const {
- if (child_id == other.child_id)
- return route_id < other.route_id;
- return child_id < other.child_id;
+ return std::tie(child_id, route_id) <
+ std::tie(other.child_id, other.route_id);
}
bool operator==(const GlobalRoutingID& other) const {
return child_id == other.child_id &&
diff --git a/content/browser/media/webrtc_identity_store_backend.cc b/content/browser/media/webrtc_identity_store_backend.cc
index 59ee816..48e51e6 100644
--- a/content/browser/media/webrtc_identity_store_backend.cc
+++ b/content/browser/media/webrtc_identity_store_backend.cc
@@ -4,6 +4,8 @@
#include "content/browser/media/webrtc_identity_store_backend.h"
+#include <tuple>
+
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/memory/scoped_vector.h"
@@ -53,8 +55,8 @@
: origin(origin), identity_name(identity_name) {}
bool operator<(const IdentityKey& other) const {
- return origin < other.origin ||
- (origin == other.origin && identity_name < other.identity_name);
+ return std::tie(origin, identity_name) <
+ std::tie(other.origin, other.identity_name);
}
GURL origin;
diff --git a/content/public/browser/desktop_media_id.h b/content/public/browser/desktop_media_id.h
index c31875b..921dc95 100644
--- a/content/public/browser/desktop_media_id.h
+++ b/content/public/browser/desktop_media_id.h
@@ -6,6 +6,7 @@
#define CONTENT_PUBLIC_BROWSER_DESKTOP_MEDIA_ID_H_
#include <string>
+#include <tuple>
#include "base/basictypes.h"
#include "content/common/content_export.h"
@@ -54,12 +55,10 @@
// Operators so that DesktopMediaID can be used with STL containers.
bool operator<(const DesktopMediaID& other) const {
#if defined(USE_AURA)
- return (type < other.type ||
- (type == other.type &&
- (id < other.id || (id == other.id &&
- aura_id < other.aura_id))));
+ return std::tie(type, id, aura_id) <
+ std::tie(other.type, other.id, other.aura_id);
#else
- return type < other.type || (type == other.type && id < other.id);
+ return std::tie(type, id) < std::tie(other.type, other.id);
#endif
}
bool operator==(const DesktopMediaID& other) const {
diff --git a/content/public/browser/global_request_id.h b/content/public/browser/global_request_id.h
index 8714b2f6..5f3f5995 100644
--- a/content/public/browser/global_request_id.h
+++ b/content/public/browser/global_request_id.h
@@ -5,6 +5,8 @@
#ifndef CONTENT_PUBLIC_BROWSER_GLOBAL_REQUEST_ID_H_
#define CONTENT_PUBLIC_BROWSER_GLOBAL_REQUEST_ID_H_
+#include <tuple>
+
namespace content {
// Uniquely identifies a net::URLRequest.
@@ -24,9 +26,8 @@
int request_id;
bool operator<(const GlobalRequestID& other) const {
- if (child_id == other.child_id)
- return request_id < other.request_id;
- return child_id < other.child_id;
+ return std::tie(child_id, request_id) <
+ std::tie(other.child_id, other.request_id);
}
bool operator==(const GlobalRequestID& other) const {
return child_id == other.child_id &&
diff --git a/content/renderer/pepper/host_var_tracker.cc b/content/renderer/pepper/host_var_tracker.cc
index e3da983..1b78ddc 100644
--- a/content/renderer/pepper/host_var_tracker.cc
+++ b/content/renderer/pepper/host_var_tracker.cc
@@ -4,6 +4,8 @@
#include "content/renderer/pepper/host_var_tracker.h"
+#include <tuple>
+
#include "base/logging.h"
#include "content/renderer/pepper/host_array_buffer_var.h"
#include "content/renderer/pepper/host_globals.h"
@@ -32,9 +34,7 @@
bool HostVarTracker::V8ObjectVarKey::operator<(
const V8ObjectVarKey& other) const {
- if (instance == other.instance)
- return hash < other.hash;
- return instance < other.instance;
+ return std::tie(instance, hash) < std::tie(other.instance, other.hash);
}
HostVarTracker::HostVarTracker()