Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: tools/gn/label.h

Issue 1461623006: Use simplify operator< implementations in tools/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix string compare checks Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/gn/location.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef TOOLS_GN_LABEL_H_ 5 #ifndef TOOLS_GN_LABEL_H_
6 #define TOOLS_GN_LABEL_H_ 6 #define TOOLS_GN_LABEL_H_
7 7
8 #include "base/containers/hash_tables.h" 8 #include "base/containers/hash_tables.h"
9 #include "tools/gn/source_dir.h" 9 #include "tools/gn/source_dir.h"
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 bool operator==(const Label& other) const { 65 bool operator==(const Label& other) const {
66 return name_ == other.name_ && dir_ == other.dir_ && 66 return name_ == other.name_ && dir_ == other.dir_ &&
67 toolchain_dir_ == other.toolchain_dir_ && 67 toolchain_dir_ == other.toolchain_dir_ &&
68 toolchain_name_ == other.toolchain_name_; 68 toolchain_name_ == other.toolchain_name_;
69 } 69 }
70 bool operator!=(const Label& other) const { 70 bool operator!=(const Label& other) const {
71 return !operator==(other); 71 return !operator==(other);
72 } 72 }
73 bool operator<(const Label& other) const { 73 bool operator<(const Label& other) const {
74 // TODO(brettw) could be optimized to avoid an extra full string check 74 if (int c = dir_.value().compare(other.dir_.value()))
75 // (one for operator==, one for <). 75 return c < 0;
76 if (dir_ != other.dir_) 76 if (int c = name_.compare(other.name_))
77 return dir_ < other.dir_; 77 return c < 0;
78 if (name_ != other.name_) 78 if (int c = toolchain_dir_.value().compare(other.toolchain_dir_.value()))
79 return name_ < other.name_; 79 return c < 0;
80 if (toolchain_dir_ != other.toolchain_dir_)
81 return toolchain_dir_ < other.toolchain_dir_;
82 return toolchain_name_ < other.toolchain_name_; 80 return toolchain_name_ < other.toolchain_name_;
83 } 81 }
84 82
85 void swap(Label& other) { 83 void swap(Label& other) {
86 dir_.swap(other.dir_); 84 dir_.swap(other.dir_);
87 name_.swap(other.name_); 85 name_.swap(other.name_);
88 toolchain_dir_.swap(other.toolchain_dir_); 86 toolchain_dir_.swap(other.toolchain_dir_);
89 toolchain_name_.swap(other.toolchain_name_); 87 toolchain_name_.swap(other.toolchain_name_);
90 } 88 }
91 89
(...skipping 24 matching lines...) Expand all
116 } 114 }
117 }; 115 };
118 116
119 } // namespace BASE_HASH_NAMESPACE 117 } // namespace BASE_HASH_NAMESPACE
120 118
121 inline void swap(Label& lhs, Label& rhs) { 119 inline void swap(Label& lhs, Label& rhs) {
122 lhs.swap(rhs); 120 lhs.swap(rhs);
123 } 121 }
124 122
125 #endif // TOOLS_GN_LABEL_H_ 123 #endif // TOOLS_GN_LABEL_H_
OLDNEW
« no previous file with comments | « no previous file | tools/gn/location.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698