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

dirstate.cpp: reduce number of lstat(".hg/dirstate") calls

Just use cached values if less than 500 ms have elapsed since last
lstat(".hg/dirstate") call

Changeset 1df8964a92f5

Parent 20e880cce2d0

by Adrian Buehlmann

Changes to one file · Browse files at 1df8964a92f5 Showing diff from parent 20e880cce2d0 Diff from another changeset...

 
185
186
187
 
188
189
 
190
191
192
 
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
 
221
222
223
 
 
224
225
226
 
234
235
236
 
237
238
239
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
241
242
 
185
186
187
188
189
 
190
191
192
193
 
203
204
205
 
 
 
 
 
 
 
 
 
 
 
206
207
208
 
211
212
213
214
215
216
217
218
 
226
227
228
229
230
231
 
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
@@ -185,8 +185,9 @@
  const dirstate* dstate;   __time64_t mtime;   std::string hgroot; + unsigned tickcount;   - entry(): dstate(0), mtime(0) {} + entry(): dstate(0), mtime(0), tickcount(0) {}   };     typedef std::list<entry>::iterator Iter; @@ -202,17 +203,6 @@
   const dirstate* dirstatecache::get(const std::string& hgroot)  { - std::string path = hgroot; - path += "/.hg/dirstate"; - - struct _stat stat; - - if (0 != lstat(path.c_str(), stat)) - { - TDEBUG_TRACE("dirstatecache::get: lstat(" << path <<") fails"); - return 0; - } -   Iter iter = _cache.begin();     for (;iter != _cache.end(); ++iter) @@ -221,6 +211,8 @@
  break;   }   + bool isnew = false; +   if (iter == _cache.end())   {   if (_cache.size() >= 10) @@ -234,9 +226,30 @@
  e.hgroot = hgroot;   _cache.push_front(e);   iter = _cache.begin(); + isnew = true;   }   - if (iter->mtime < stat.st_mtime) + unsigned tc = GetTickCount(); + + std::string path = hgroot +"/.hg/dirstate"; + + struct _stat stat; + + bool stat_done = false; + + if (isnew || (tc - iter->tickcount) > 500) + { + if (0 != lstat(path.c_str(), stat)) + { + TDEBUG_TRACE("dirstatecache::get: lstat(" << path <<") failed"); + return 0; + } + iter->tickcount = tc; + stat_done = true; + TDEBUG_TRACE("dirstatecache::get: lstat(" << path <<") ok "); + } + + if (stat_done && iter->mtime < stat.st_mtime)   {   iter->mtime = stat.st_mtime;   if (iter->dstate) {