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 getdir()

Changeset 5ab289f25d6a

Parent a58fba69ec2d

by Adrian Buehlmann

Changes to one file · Browse files at 5ab289f25d6a Showing diff from parent a58fba69ec2d Diff from another changeset...

 
158
159
160
161
 
162
163
164
165
166
 
 
 
 
167
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
 
158
159
160
 
161
162
163
164
165
 
166
167
168
169
170
 
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
199
200
@@ -158,31 +158,43 @@
 }     -Directory* Directory::getdir(const std::string& n) +Directory* Directory::getdir(const std::string& n_in)  {   std::string base;   std::string rest;   - if (!splitbase(n, base, rest)) + std::string n = n_in; + const Directory* cur = this; + + for (;;)   { - TDEBUG_TRACE("Directory(" << path() << ")::getdir(" << n << "): splitbase returned 0"); + loopstart: + + if (!splitbase(n, base, rest)) + { + TDEBUG_TRACE("Directory(" << path() << ")::getdir(" + << n_in << "): splitbase returned 0"); + return 0; + } + + const bool leaf = base.empty(); + const std::string& searchstr = (leaf ? n : base); + + for (DirsT::const_iterator i = cur->subdirs_.begin(); + i != cur->subdirs_.end(); ++i) + { + if ((*i)->name_ == searchstr) + { + if (leaf) + return *i; + cur = *i; + n = rest; + goto loopstart; + } + } +   return 0;   } - - const bool leaf = base.empty(); - const std::string& searchstr = (leaf ? n : base); - - for (DirsT::const_iterator i = subdirs_.begin(); i != subdirs_.end(); ++i) - { - if ((*i)->name_ == searchstr) - { - if (leaf) - return *i; - return (*i)->getdir(rest); - } - } - - return 0;  }