+ unsigned postot, // total non-trivial calls to PosToImpl
+ poshits, // cache hits from PosToImpl()
+ mishits, // cached position beyond the needed one
+ sumpos, // sum of all positions, used to compute the
+ // average position after dividing by postot
+ sumofs, // sum of all offsets after using the cache, used to
+ // compute the average after dividing by hits
+ lentot, // number of total calls to length()
+ lenhits; // number of cache hits in length()
+ } ms_cacheStats;
+
+ friend struct wxStrCacheStatsDumper;
+
+ #define wxCACHE_PROFILE_FIELD_INC(field) ms_cacheStats.field++
+ #define wxCACHE_PROFILE_FIELD_ADD(field, val) ms_cacheStats.field += (val)
+#else // !wxPROFILE_STRING_CACHE
+ #define wxCACHE_PROFILE_FIELD_INC(field)
+ #define wxCACHE_PROFILE_FIELD_ADD(field, val)
+#endif // wxPROFILE_STRING_CACHE/!wxPROFILE_STRING_CACHE
+
+ // note: it could seem that the functions below shouldn't be inline because
+ // they are big, contain loops and so the compiler shouldn't be able to
+ // inline them anyhow, however moving them into string.cpp does decrease the
+ // code performance by ~5%, at least when using g++ 4.1 so do keep them here
+ // unless tests show that it's not advantageous any more
+
+ // return the pointer to the cache element for this string or NULL if not
+ // cached
+ Cache::Element *FindCacheElement() const
+ {
+ // profiling seems to show a small but consistent gain if we use this
+ // simple loop instead of starting from the last used element (there are
+ // a lot of misses in this function...)
+ Cache::Element * const cacheBegin = GetCacheBegin();
+#ifndef wxHAS_COMPILER_TLS
+ // during destruction tls calls may return NULL, in this case return NULL
+ // immediately without accessing anything else
+ if ( cacheBegin == NULL )
+ return NULL;
+#endif
+ Cache::Element * const cacheEnd = GetCacheEnd();
+ for ( Cache::Element *c = cacheBegin; c != cacheEnd; c++ )
+ {
+ if ( c->str == this )
+ return c;
+ }