@@ -217,13 +217,8 @@ void Module::UpdateNewlyAddedTypes()
217217 }
218218 CONTRACTL_END
219219
220- DWORD countTypesAfterProfilerUpdate = GetMDImport ()->GetCountWithTokenKind (mdtTypeDef);
221- DWORD countExportedTypesAfterProfilerUpdate = GetMDImport ()->GetCountWithTokenKind (mdtExportedType);
222- DWORD countCustomAttributeCount = GetMDImport ()->GetCountWithTokenKind (mdtCustomAttribute);
223-
224- if (m_dwTypeCount == countTypesAfterProfilerUpdate
225- && m_dwExportedTypeCount == countExportedTypesAfterProfilerUpdate
226- && m_dwCustomAttributeCount == countCustomAttributeCount)
220+ TypeCounts currTypeCounts = GetCurrentTypeCounts ();
221+ if (m_typeCounts == currTypeCounts)
227222 {
228223 // The profiler added no new types, do not create the in memory hashes
229224 return ;
@@ -242,27 +237,39 @@ void Module::UpdateNewlyAddedTypes()
242237 // If the hash tables already exist (either R2R and we've previously populated the ) we need to manually add the types.
243238
244239 // typeDefs rids 0 and 1 aren't included in the count, thus X typeDefs before means rid X+1 was valid and our incremental addition should start at X+2
245- for (DWORD typeDefRid = m_dwTypeCount + 2 ; typeDefRid < countTypesAfterProfilerUpdate + 2 ; typeDefRid++)
240+ for (DWORD typeDefRid = m_typeCounts. TypeCount + 2 ; typeDefRid < currTypeCounts. TypeCount + 2 ; typeDefRid++)
246241 {
247242 GetAssembly ()->AddType (this , TokenFromRid (typeDefRid, mdtTypeDef));
248243 }
249244
250245 // exportedType rid 0 isn't included in the count, thus X exportedTypes before means rid X was valid and our incremental addition should start at X+1
251- for (DWORD exportedTypeDef = m_dwExportedTypeCount + 1 ; exportedTypeDef < countExportedTypesAfterProfilerUpdate + 1 ; exportedTypeDef++)
246+ for (DWORD exportedTypeDef = m_typeCounts. ExportedTypeCount + 1 ; exportedTypeDef < currTypeCounts. ExportedTypeCount + 1 ; exportedTypeDef++)
252247 {
253248 GetAssembly ()->AddExportedType (TokenFromRid (exportedTypeDef, mdtExportedType));
254249 }
255250
256- if ((countCustomAttributeCount != m_dwCustomAttributeCount ) && IsReadyToRun ())
251+ if ((currTypeCounts. CustomAttributeCount != m_typeCounts. CustomAttributeCount ) && IsReadyToRun ())
257252 {
258253 // Set of custom attributes has changed. Disable the cuckoo filter from ready to run, and do normal custom attribute parsing
259254 GetReadyToRunInfo ()->DisableCustomAttributeFilter ();
260255 }
261256 }
262257
263- m_dwTypeCount = countTypesAfterProfilerUpdate;
264- m_dwExportedTypeCount = countExportedTypesAfterProfilerUpdate;
265- m_dwCustomAttributeCount = countCustomAttributeCount;
258+ m_typeCounts = currTypeCounts;
259+ }
260+
261+ Module::TypeCounts Module::GetCurrentTypeCounts ()
262+ {
263+ WRAPPER_NO_CONTRACT ;
264+
265+ IMDInternalImport* pMDImport = GetMDImport ();
266+ _ASSERTE (pMDImport != NULL );
267+
268+ TypeCounts typeCounts;
269+ typeCounts.TypeCount = pMDImport->GetCountWithTokenKind (mdtTypeDef);
270+ typeCounts.ExportedTypeCount = pMDImport->GetCountWithTokenKind (mdtExportedType);
271+ typeCounts.CustomAttributeCount = pMDImport->GetCountWithTokenKind (mdtCustomAttribute);
272+ return typeCounts;
266273}
267274#endif // PROFILING_SUPPORTED || FEATURE_METADATA_UPDATER
268275
@@ -282,10 +289,8 @@ void Module::NotifyProfilerLoadFinished(HRESULT hr)
282289 // the profiler once.
283290 if (SetTransientFlagInterlocked (IS_PROFILER_NOTIFIED ))
284291 {
285- // Record how many types are already present
286- m_dwTypeCount = GetMDImport ()->GetCountWithTokenKind (mdtTypeDef);
287- m_dwExportedTypeCount = GetMDImport ()->GetCountWithTokenKind (mdtExportedType);
288- m_dwCustomAttributeCount = GetMDImport ()->GetCountWithTokenKind (mdtCustomAttribute);
292+ // Initialize how many types are already present
293+ m_typeCounts = GetCurrentTypeCounts ();
289294
290295 BOOL profilerCallbackHappened = FALSE ;
291296 // Notify the profiler, this may cause metadata to be updated
@@ -498,15 +503,11 @@ void Module::Initialize(AllocMemTracker *pamTracker, LPCWSTR szName)
498503 }
499504
500505#if defined(PROFILING_SUPPORTED_DATA) || defined(FEATURE_METADATA_UPDATER)
501- #ifdef PROFILING_SUPPORTED
502- // These will be initialized in NotifyProfilerLoadFinished.
503- m_dwTypeCount = 0 ;
504- m_dwExportedTypeCount = 0 ;
505- m_dwCustomAttributeCount = 0 ;
506+ #if defined(PROFILING_SUPPORTED)
507+ // These will be updated in NotifyProfilerLoadFinished for profiling scenarios.
508+ m_typeCounts = {};
506509#else
507- m_dwTypeCount = GetMDImport ()->GetCountWithTokenKind (mdtTypeDef);
508- m_dwExportedTypeCount = GetMDImport ()->GetCountWithTokenKind (mdtExportedType);
509- m_dwCustomAttributeCount = GetMDImport ()->GetCountWithTokenKind (mdtCustomAttribute);
510+ m_typeCounts = GetCurrentTypeCounts ();
510511#endif // PROFILING_SUPPORTED
511512#endif // PROFILING_SUPPORTED_DATA || FEATURE_METADATA_UPDATER
512513
0 commit comments