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

shellext: cache icon handles in GetTortoiseIcon (issue 399)

Changeset 49f6846acc09

Parent ceb5521c0ab2

by Adrian Buehlmann

Changes to one file · Browse files at 49f6846acc09 Showing diff from parent ceb5521c0ab2 Diff from another changeset...

 
3
4
5
 
6
7
8
 
177
178
179
 
180
181
 
 
 
182
183
184
185
186
 
187
188
189
 
 
 
 
 
 
 
 
 
 
 
 
190
191
192
193
194
 
 
195
196
 
 
 
 
 
 
 
 
197
198
199
 
3
4
5
6
7
8
9
 
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
203
204
205
206
207
208
209
 
210
211
212
 
213
214
215
216
217
218
219
220
221
222
223
@@ -3,6 +3,7 @@
   #include <vector>  #include <assert.h> +#include <map>    #include <io.h>  #include "FCNTL.H" @@ -177,23 +178,46 @@
 }     +// not reentrant  HICON GetTortoiseIcon(const std::string& iconname)  { + typedef std::map<std::string, HICON> IconCacheT; + static IconCacheT iconcache_; +   std::string thgdir = GetTHgProgRoot();   if (thgdir.empty())   {   TDEBUG_TRACE("GetTortoiseIcon: THG root is empty"); - return NULL; + return 0;   }   - std::string iconpath = thgdir + "\\icons\\" + iconname; + const std::string iconpath = thgdir + "\\icons\\" + iconname; + + IconCacheT::const_iterator i = iconcache_.find(iconpath); + if (i != iconcache_.end()) + return i->second; + + if (iconcache_.size() > 200) + { + TDEBUG_TRACE("**** GetTortoiseIcon: error: too many icons in cache"); + return 0; + } +   HICON h = (HICON) LoadImageA(0, iconpath.c_str(), IMAGE_ICON,   16, 16, LR_LOADFROMFILE);   if (!h)   { - TDEBUG_TRACE(" GetTortoiseIcon: can't find " + iconpath); + TDEBUG_TRACE("GetTortoiseIcon: can't find " + iconpath); + return 0;   } - + + iconcache_[iconpath] = h; + + TDEBUG_TRACE( + "GetTortoiseIcon: added '" << iconpath << "' to iconcache_" + " (" << iconcache_.size() << " icons in cache)" + ); +   return h;  }