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

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

Issue 610043002: Convert GN's deps iterator to work with range-based for loops. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/deps_iterator.h" 5 #include "tools/gn/deps_iterator.h"
6 6
7 #include "tools/gn/target.h" 7 #include "tools/gn/target.h"
8 8
9 DepsIterator::DepsIterator(const Target* t) : current_index_(0) { 9 DepsIterator::DepsIterator() : current_index_(0) {
10 vect_stack_[0] = &t->public_deps(); 10 vect_stack_[0] = nullptr;
11 vect_stack_[1] = &t->private_deps(); 11 vect_stack_[1] = nullptr;
12 vect_stack_[2] = &t->data_deps(); 12 vect_stack_[2] = nullptr;
13
14 if (vect_stack_[0]->empty())
15 Advance();
16 } 13 }
17 14
18 // Iterate over the public and private linked deps, but not the data deps. 15 DepsIterator::DepsIterator(const LabelTargetVector* a,
19 DepsIterator::DepsIterator(const Target* t, LinkedOnly) : current_index_(0) { 16 const LabelTargetVector* b,
20 vect_stack_[0] = &t->public_deps(); 17 const LabelTargetVector* c)
21 vect_stack_[1] = &t->private_deps(); 18 : current_index_(0) {
22 vect_stack_[2] = NULL; 19 vect_stack_[0] = a;
20 vect_stack_[1] = b;
21 vect_stack_[2] = c;
23 22
24 if (vect_stack_[0]->empty()) 23 if (vect_stack_[0] && vect_stack_[0]->empty())
25 Advance(); 24 operator++();
26 } 25 }
27 26
28 // Advance to the next position. This assumes there are more vectors. 27 // Advance to the next position. This assumes there are more vectors.
29 // 28 //
30 // For internal use, this function tolerates an initial index equal to the 29 // For internal use, this function tolerates an initial index equal to the
31 // length of the current vector. In this case, it will advance to the next 30 // length of the current vector. In this case, it will advance to the next
32 // one. 31 // one.
33 void DepsIterator::Advance() { 32 DepsIterator& DepsIterator::operator++() {
34 DCHECK(vect_stack_[0]); 33 DCHECK(vect_stack_[0]);
35 34
36 current_index_++; 35 current_index_++;
37 if (current_index_ >= vect_stack_[0]->size()) { 36 if (current_index_ >= vect_stack_[0]->size()) {
38 // Advance to next vect. Shift the elements left by one. 37 // Advance to next vect. Shift the elements left by one.
39 vect_stack_[0] = vect_stack_[1]; 38 vect_stack_[0] = vect_stack_[1];
40 vect_stack_[1] = vect_stack_[2]; 39 vect_stack_[1] = vect_stack_[2];
41 vect_stack_[2] = NULL; 40 vect_stack_[2] = nullptr;
42 41
43 current_index_ = 0; 42 current_index_ = 0;
44 43
45 if (vect_stack_[0] && vect_stack_[0]->empty()) 44 if (vect_stack_[0] && vect_stack_[0]->empty())
46 Advance(); 45 operator++();
47 } 46 }
47 return *this;
48 } 48 }
49
50 DepsIteratorRange::DepsIteratorRange(const DepsIterator& b)
51 : begin_(b),
52 end_() {
53 }
54
55 DepsIteratorRange::~DepsIteratorRange() {
56 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698