Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.8, 0.8.1, and 0.8.2

Directory: eliminate call recursion in add()

Changeset b87f2f8e1875

Parent 0d28542b5ed2

by Adrian Buehlmann

Changes to one file · Browse files at b87f2f8e1875 Showing diff from parent 0d28542b5ed2 Diff from another changeset...

 
64
65
66
67
 
68
69
70
 
 
 
 
 
 
71
72
73
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
 
64
65
66
 
67
68
69
70
71
72
73
74
75
76
77
 
 
 
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
111
112
@@ -64,39 +64,49 @@
 }     -int Directory::add(const std::string& n, Direntry& e) +int Directory::add(const std::string& n_in, Direntry& e)  {   std::string base;   std::string rest; + + std::string n = n_in; + Directory* cur = this; + + for (;;) + {   - if (!splitbase(n, base, rest)) { - TDEBUG_TRACE("Directory(" << path() << ")::add(" << n << "): splitbase returned 0"); - return 0; + if (!splitbase(n, base, rest)) { + TDEBUG_TRACE("Directory(" << path() << ")::add(" << n_in + << "): splitbase returned 0"); + return 0; + } + + if (base.empty()) + { + e.name = n; + cur->files_.push_back(e); + return 1; + } + + Directory* d = 0; + for (DirsT::iterator i = cur->subdirs_.begin(); + i != cur->subdirs_.end(); ++i) + { + if ((*i)->name_ == base) { + d = *i; + break; + } + } + + if (!d) + { + d = new Directory(cur, base, cur->path()); + cur->subdirs_.push_back(d); + } + + n = rest; + cur = d;   } - - if (base.empty()) - { - e.name = n; - files_.push_back(e); - return 1; - } - - Directory* d = 0; - for (DirsT::iterator i = subdirs_.begin(); i != subdirs_.end(); ++i) - { - if ((*i)->name_ == base) { - d = *i; - break; - } - } - - if (!d) - { - d = new Directory(this, base, path()); - subdirs_.push_back(d); - } - - return d->add(rest, e);  }