Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions src/System.Management.Automation/engine/DataStoreAdapterProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,35 @@ internal string FullName
{
get
{
string GetFullName(string name, string psSnapInName, string moduleName)
{
string result = name;
if (!string.IsNullOrEmpty(psSnapInName))
{
result =
string.Format(
System.Globalization.CultureInfo.InvariantCulture,
"{0}\\{1}",
psSnapInName,
name);
}

// After converting core snapins to load as modules, the providers will have Module property populated
else if (!string.IsNullOrEmpty(moduleName))
{
result =
string.Format(
System.Globalization.CultureInfo.InvariantCulture,
"{0}\\{1}",
moduleName,
name);
}
return _fullName ?? (_fullName = GetFullName());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name is still cached. But does it make sens to caching this name at all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comes from #8831 where we add the optimization. It is amazing to calculate the full name for every provider operation. I'd do not revert the optimization.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it's not a problem to use the cached name in other places but only those 2 spots you changed in this PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is important to do not cache the provider full name in the submodule until we set root module name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it would be very helpful to add comments to the place where you use GetFullName() instead of the cached fullname, otherwise, another refactoring in future might change it back to use the cached value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is already there "Use GetFullName() to avoid caching full name at init time."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, I missed that. Can you please also add the information about why to avoid the cached name?

}
}

return result;
}
internal string GetFullName()
{
string result = Name;
if (!string.IsNullOrEmpty(PSSnapInName))
{
result =
string.Format(
System.Globalization.CultureInfo.InvariantCulture,
"{0}\\{1}",
PSSnapInName,
Name);
}

return _fullName ?? (_fullName = GetFullName(Name, PSSnapInName, ModuleName));
// After converting core snapins to load as modules, the providers will have Module property populated
else if (!string.IsNullOrEmpty(ModuleName))
{
result =
string.Format(
System.Globalization.CultureInfo.InvariantCulture,
"{0}\\{1}",
ModuleName,
Name);
}

return result;
}

/// <summary>
Expand Down Expand Up @@ -411,10 +411,10 @@ internal ProviderInfo(

// Create the hidden drive. The name doesn't really
// matter since we are not adding this drive to a scope.

// Use GetFullName() to avoid caching full name at init time.
_hiddenDrive =
new PSDriveInfo(
this.FullName,
GetFullName(),
this,
string.Empty,
string.Empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,8 @@ internal void InitializeProvider(
}

// Only mount drives for the current provider

if (!provider.NameEquals(newDrive.Provider.FullName))
// Use GetFullName() to avoid caching full name at init time.
if (!provider.NameEquals(newDrive.Provider.GetFullName()))
{
continue;
}
Expand Down