| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "courgette/label_manager.h" | 5 #include "courgette/label_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 VLOG(1) << " infill " << count; | 91 VLOG(1) << " infill " << count; |
| 92 } | 92 } |
| 93 | 93 |
| 94 LabelManager::LabelManager() {} | 94 LabelManager::LabelManager() {} |
| 95 | 95 |
| 96 LabelManager::~LabelManager() {} | 96 LabelManager::~LabelManager() {} |
| 97 | 97 |
| 98 // static | 98 // static |
| 99 int LabelManager::GetIndexBound(const RVAToLabel& labels_map) { | |
| 100 int max_index = -1; | |
| 101 for (const auto& rva_and_label : labels_map) { | |
| 102 const Label& label = *rva_and_label.second; | |
| 103 if (label.index_ != Label::kNoIndex) | |
| 104 max_index = std::max(max_index, label.index_); | |
| 105 } | |
| 106 return max_index + 1; | |
| 107 } | |
| 108 | |
| 109 // static | |
| 110 int LabelManager::GetLabelIndexBound(const LabelVector& labels) { | 99 int LabelManager::GetLabelIndexBound(const LabelVector& labels) { |
| 111 int max_index = -1; | 100 int max_index = -1; |
| 112 for (const Label& label : labels) { | 101 for (const Label& label : labels) { |
| 113 if (label.index_ != Label::kNoIndex) | 102 if (label.index_ != Label::kNoIndex) |
| 114 max_index = std::max(max_index, label.index_); | 103 max_index = std::max(max_index, label.index_); |
| 115 } | 104 } |
| 116 return max_index + 1; | 105 return max_index + 1; |
| 117 } | 106 } |
| 118 | 107 |
| 119 // Uses binary search to find |rva|. | 108 // Uses binary search to find |rva|. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 DCHECK(labels_.empty()); | 176 DCHECK(labels_.empty()); |
| 188 labels_.reserve(num_distinct_rva); | 177 labels_.reserve(num_distinct_rva); |
| 189 for (CRV it(rvas.begin(), rvas.end()); it.has_more(); it.advance()) { | 178 for (CRV it(rvas.begin(), rvas.end()); it.has_more(); it.advance()) { |
| 190 labels_.push_back(Label(*it.cur())); | 179 labels_.push_back(Label(*it.cur())); |
| 191 base::CheckedNumeric<uint32_t> count = it.repeat(); | 180 base::CheckedNumeric<uint32_t> count = it.repeat(); |
| 192 labels_.back().count_ = count.ValueOrDie(); | 181 labels_.back().count_ = count.ValueOrDie(); |
| 193 } | 182 } |
| 194 } | 183 } |
| 195 | 184 |
| 196 } // namespace courgette | 185 } // namespace courgette |
| OLD | NEW |