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

Side by Side Diff: tools/gn/location.cc

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 | « tools/gn/label.h ('k') | no next file » | 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 #include "tools/gn/location.h" 5 #include "tools/gn/location.h"
6 6
7 #include <tuple>
8
7 #include "base/logging.h" 9 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
9 #include "tools/gn/input_file.h" 11 #include "tools/gn/input_file.h"
10 12
11 Location::Location() 13 Location::Location()
12 : file_(nullptr), 14 : file_(nullptr),
13 line_number_(-1), 15 line_number_(-1),
14 char_offset_(-1) { 16 char_offset_(-1) {
15 } 17 }
16 18
(...skipping 12 matching lines...) Expand all
29 other.line_number_ == line_number_ && 31 other.line_number_ == line_number_ &&
30 other.char_offset_ == char_offset_; 32 other.char_offset_ == char_offset_;
31 } 33 }
32 34
33 bool Location::operator!=(const Location& other) const { 35 bool Location::operator!=(const Location& other) const {
34 return !operator==(other); 36 return !operator==(other);
35 } 37 }
36 38
37 bool Location::operator<(const Location& other) const { 39 bool Location::operator<(const Location& other) const {
38 DCHECK(file_ == other.file_); 40 DCHECK(file_ == other.file_);
39 if (line_number_ != other.line_number_) 41 return std::tie(line_number_, char_offset_) <
40 return line_number_ < other.line_number_; 42 std::tie(other.line_number_, other.char_offset_);
41 return char_offset_ < other.char_offset_;
42 } 43 }
43 44
44 std::string Location::Describe(bool include_char_offset) const { 45 std::string Location::Describe(bool include_char_offset) const {
45 if (!file_) 46 if (!file_)
46 return std::string(); 47 return std::string();
47 48
48 std::string ret; 49 std::string ret;
49 if (file_->friendly_name().empty()) 50 if (file_->friendly_name().empty())
50 ret = file_->name().value(); 51 ret = file_->name().value();
51 else 52 else
(...skipping 16 matching lines...) Expand all
68 end_(end) { 69 end_(end) {
69 DCHECK(begin_.file() == end_.file()); 70 DCHECK(begin_.file() == end_.file());
70 } 71 }
71 72
72 LocationRange LocationRange::Union(const LocationRange& other) const { 73 LocationRange LocationRange::Union(const LocationRange& other) const {
73 DCHECK(begin_.file() == other.begin_.file()); 74 DCHECK(begin_.file() == other.begin_.file());
74 return LocationRange( 75 return LocationRange(
75 begin_ < other.begin_ ? begin_ : other.begin_, 76 begin_ < other.begin_ ? begin_ : other.begin_,
76 end_ < other.end_ ? other.end_ : end_); 77 end_ < other.end_ ? other.end_ : end_);
77 } 78 }
OLDNEW
« no previous file with comments | « tools/gn/label.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698