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: cache result of Directory::status()

Cached value is valid for 3 seconds

Changeset 62d0677c34ce

Parent 7658c2335d00

by Adrian Buehlmann

Changes to one file · Browse files at 62d0677c34ce Showing diff from parent 7658c2335d00 Diff from another changeset...

 
100
101
102
 
 
 
103
104
105
 
 
106
107
108
 
115
116
117
 
 
 
118
119
120
 
126
127
128
 
129
130
131
 
258
259
260
261
 
262
263
264
265
266
267
 
268
269
270
 
279
280
281
282
 
 
283
284
285
 
298
299
300
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
301
302
303
 
100
101
102
103
104
105
106
107
 
108
109
110
111
112
 
119
120
121
122
123
124
125
126
127
 
133
134
135
136
137
138
139
 
266
267
268
 
269
270
271
272
273
274
 
275
276
277
278
 
287
288
289
 
290
291
292
293
294
 
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
@@ -100,9 +100,13 @@
    DirsT subdirs_;   FilesT files_; + + unsigned tickcount_; + char status_;    public: - Directory(Directory* p, const std::string& n): parent_(p), name_(n) {} + Directory(Directory* p, const std::string& n): + parent_(p), name_(n), tickcount_(0), status_(-1) {}   ~Directory();     std::string path(const std::string& n = "") const; @@ -115,6 +119,9 @@
  char status(const std::string& hgroot);     void print() const; + +private: + char status_imp(const std::string& hgroot);  };     @@ -126,6 +133,7 @@
  }  }   +  int splitbase(const std::string& n, std::string& base, std::string& rest)  {   if (n.empty()) @@ -258,13 +266,13 @@
 }     -char Directory::status(const std::string& hgroot) +char Directory::status_imp(const std::string& hgroot)  {   bool added = false;     for (DirsT::iterator i = subdirs_.begin(); i != subdirs_.end(); ++i)   { - char s = (*i)->status(hgroot); + char s = (*i)->status_imp(hgroot);   if (s == 'M')   return 'M';   if (s == 'A') @@ -279,7 +287,8 @@
    if (0 != lstat(p.c_str(), stat))   { - TDEBUG_TRACE("Directory(" << path() << ")::status: lstat(" << p << ") failed"); + TDEBUG_TRACE("Directory(" << path() + << ")::status_imp: lstat(" << p << ") failed");   continue;   }   @@ -298,6 +307,23 @@
 }     +char Directory::status(const std::string& hgroot) +{ + if (status_ != -1) + { + unsigned tc = GetTickCount(); + if (tc - tickcount_ < 3000) { + return status_; + } + } + + status_ = status_imp(hgroot); + tickcount_ = GetTickCount(); + + return status_; +} + +  void Directory::print() const  {   for (DirsT::const_iterator i = subdirs_.begin(); i != subdirs_.end(); ++i)