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

Changeset a58fba69ec2d

Parent b87f2f8e1875

by Adrian Buehlmann

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

 
110
111
112
113
 
114
115
116
117
118
 
 
 
 
119
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
 
110
111
112
 
113
114
115
116
117
 
118
119
120
121
122
 
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
159
160
@@ -110,35 +110,51 @@
 }     -const Direntry* Directory::get(const std::string& n) const +const Direntry* Directory::get(const std::string& n_in) const  {   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() << ")::get(" << n << "): splitbase returned 0"); + loopstart: + + if (!splitbase(n, base, rest)) + { + TDEBUG_TRACE("Directory(" << path() << ")::get(" + << n_in << "): splitbase returned 0"); + return 0; + } + + if (base.empty()) + { + for (FilesT::const_iterator i = cur->files_.begin(); + i != cur->files_.end(); ++i) + { + if (i->name == n) + return &(*i); + } + return 0; + } + + for (DirsT::const_iterator i = cur->subdirs_.begin(); + i != cur->subdirs_.end(); ++i) + { + if ((*i)->name_ == base) + { + cur = *i; + n = rest; + goto loopstart; + } + } + + TDEBUG_TRACE("Directory(" << path() << ")::get(" + << n_in << "): unknown subdir");   return 0;   } - - if (base.empty()) - { - for (FilesT::const_iterator i = files_.begin(); i != files_.end(); ++i) - { - if (i->name == n) - return &(*i); - } - return 0; - } - - for (DirsT::const_iterator i = subdirs_.begin(); i != subdirs_.end(); ++i) - { - if ((*i)->name_ == base) - return (*i)->get(rest); - } - - TDEBUG_TRACE("Directory(" << path() << ")::get(" << n << "): unknown subdir"); - return 0;  }