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: use std::list for dirstatecache

Changeset 56d3e8623219

Parent ce01b18d503e

by Adrian Buehlmann

Changes to one file · Browse files at 56d3e8623219 Showing diff from parent ce01b18d503e Diff from another changeset...

 
24
25
26
 
27
28
29
 
100
101
102
103
104
105
106
 
 
 
 
 
107
108
109
 
 
 
 
 
 
 
110
111
112
113
114
115
116
117
118
119
120
 
121
122
123
 
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
201
202
 
24
25
26
27
28
29
30
 
101
102
103
 
 
 
 
104
105
106
107
108
109
 
 
110
111
112
113
114
115
116
117
118
 
 
 
 
 
 
119
120
 
121
122
123
124
 
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
201
202
@@ -24,6 +24,7 @@
 #include <sys/stat.h>    #include <vector> +#include <list>      #ifdef WIN32 @@ -100,24 +101,24 @@
   class dirstatecache  { - const dirstate* dstate; - dirstatecache* next; - __time64_t mtime; - std::string path; + struct entry + { + const dirstate* dstate; + __time64_t mtime; + std::string path;   - dirstatecache(): dstate(0), next(0), mtime(0) {} - + entry(): dstate(0), mtime(0) {} + }; + + typedef std::list<entry>::iterator Iter; + + static std::list<entry> _cache; +  public:   static const dirstate* get(const char* hgroot); - -private: - static dirstatecache* _cache; - - dirstatecache(const dirstatecache&); // not implemented - dirstatecache& operator=(const dirstatecache&); // not implemented  };   -dirstatecache* dirstatecache::_cache = 0; +std::list<dirstatecache::entry> dirstatecache::_cache;      std::auto_ptr<dirstate> dirstate::read(const char *path) @@ -171,32 +172,31 @@
    if (0 != lstat(path.c_str(), &stat))   return 0; + + Iter iter = _cache.begin();   - dirstatecache* head = _cache; - while (head) + for (;iter != _cache.end(); ++iter)   { - if (strncmp(path.c_str(), head->path.c_str(), MAX_PATH) == 0) + if (strncmp(path.c_str(), iter->path.c_str(), MAX_PATH) == 0)   break; - head = head->next;   }   - if (!head) - { - head = new dirstatecache(); - head->next = _cache; - _cache = head; - head->path = path; + if (iter == _cache.end()) + { + entry e; + e.path = path; + iter = _cache.insert(iter, e);   }   - if (head->mtime < stat.st_mtime) + if (iter->mtime < stat.st_mtime)   { - head->mtime = stat.st_mtime; - if (head->dstate) - delete head->dstate; - head->dstate = dirstate::read(path.c_str()).release(); + iter->mtime = stat.st_mtime; + if (iter->dstate) + delete iter->dstate; + iter->dstate = dirstate::read(path.c_str()).release();   }   - return head->dstate; + return iter->dstate;  }