New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize RAR's GetReferenceItems method #5929
Changes from 1 commit
cfe147c
17015af
fec708e
ed2bc5c
2fc517f
1dc3bc5
77b1038
507214d
4945ad2
cf314ab
7077b0e
afe2cf0
9dccb26
147ef43
2901929
fd0a93d
74cf67c
8a45a46
2a8893c
04e72ed
2bb3210
ff501aa
2f23808
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2617,38 +2617,6 @@ private ITaskItem SetItemMetadata(List<ITaskItem> relatedItems, List<ITaskItem> | |
referenceItem.SetMetadata(ItemMetadataNames.imageRuntime, reference.ImageRuntime); | ||
} | ||
|
||
if (reference.IsWinMDFile) | ||
{ | ||
referenceItem.SetMetadata(ItemMetadataNames.winMDFile, "true"); | ||
|
||
// The ImplementationAssembly is only set if the implementation file exits on disk | ||
if (reference.ImplementationAssembly != null) | ||
{ | ||
if (VerifyArchitectureOfImplementationDll(reference.ImplementationAssembly, reference.FullPath)) | ||
{ | ||
referenceItem.SetMetadata(ItemMetadataNames.winmdImplmentationFile, Path.GetFileName(reference.ImplementationAssembly)); | ||
|
||
// Add the implementation item as a related file | ||
ITaskItem item = new TaskItem(reference.ImplementationAssembly); | ||
// Clone metadata. | ||
referenceItem.CopyMetadataTo(item); | ||
RemoveNonForwardableMetadata(item); | ||
|
||
// Add the related item. | ||
relatedItems.Add(item); | ||
} | ||
} | ||
|
||
if (reference.IsManagedWinMDFile) | ||
{ | ||
referenceItem.SetMetadata(ItemMetadataNames.winMDFileType, "Managed"); | ||
} | ||
else | ||
{ | ||
referenceItem.SetMetadata(ItemMetadataNames.winMDFileType, "Native"); | ||
} | ||
} | ||
|
||
// The redist root is "null" when there was no IsRedistRoot flag in the Redist XML | ||
// (or there was no redist XML at all for this item). | ||
if (reference.IsRedistRoot != null) | ||
|
@@ -2715,55 +2683,58 @@ private ITaskItem SetItemMetadata(List<ITaskItem> relatedItems, List<ITaskItem> | |
// Unset fusionName so we don't have to unset it later. | ||
referenceItem.RemoveMetadata(ItemMetadataNames.fusionName); | ||
|
||
List<string> relatedFileExtensions = reference.GetRelatedFileExtensions(); | ||
List<string> satellites = reference.GetSatelliteFiles(); | ||
List<string> serializationAssemblyFiles = reference.GetSerializationAssemblyFiles(); | ||
string[] scatterFiles = reference.GetScatterFiles(); | ||
Dictionary<string, string> nonForwardableMetadata = null; | ||
if (relatedFileExtensions.Count > 0 || satellites.Count > 0 || serializationAssemblyFiles.Count > 0 || scatterFiles.Length > 0) | ||
{ | ||
// Unset non-forwardable metadata now so we don't have to do it for individual items. | ||
nonForwardableMetadata = RemoveNonForwardableMetadata(referenceItem); | ||
} | ||
|
||
// Now clone all properties onto the related files. | ||
foreach (string relatedFileExtension in reference.GetRelatedFileExtensions()) | ||
foreach (string relatedFileExtension in relatedFileExtensions) | ||
{ | ||
ITaskItem item = new TaskItem(reference.FullPathWithoutExtension + relatedFileExtension); | ||
// Clone metadata. | ||
referenceItem.CopyMetadataTo(item); | ||
// Related files don't have a fusion name. | ||
RemoveNonForwardableMetadata(item); | ||
|
||
// Add the related item. | ||
relatedItems.Add(item); | ||
} | ||
|
||
// Set up the satellites. | ||
foreach (string satelliteFile in reference.GetSatelliteFiles()) | ||
foreach (string satelliteFile in satellites) | ||
{ | ||
ITaskItem item = new TaskItem(Path.Combine(reference.DirectoryName, satelliteFile)); | ||
// Clone metadata. | ||
referenceItem.CopyMetadataTo(item); | ||
// Set the destination directory. | ||
item.SetMetadata(ItemMetadataNames.destinationSubDirectory, FileUtilities.EnsureTrailingSlash(Path.GetDirectoryName(satelliteFile))); | ||
// Satellite files don't have a fusion name. | ||
RemoveNonForwardableMetadata(item); | ||
|
||
// Add the satellite item. | ||
satelliteItems.Add(item); | ||
} | ||
|
||
// Set up the serialization assemblies | ||
foreach (string serializationAssemblyFile in reference.GetSerializationAssemblyFiles()) | ||
foreach (string serializationAssemblyFile in serializationAssemblyFiles) | ||
{ | ||
ITaskItem item = new TaskItem(Path.Combine(reference.DirectoryName, serializationAssemblyFile)); | ||
// Clone metadata. | ||
referenceItem.CopyMetadataTo(item); | ||
// serialization assemblies files don't have a fusion name. | ||
RemoveNonForwardableMetadata(item); | ||
|
||
// Add the serialization assembly item. | ||
serializationAssemblyItems.Add(item); | ||
} | ||
|
||
// Set up the scatter files. | ||
foreach (string scatterFile in reference.GetScatterFiles()) | ||
foreach (string scatterFile in scatterFiles) | ||
{ | ||
ITaskItem item = new TaskItem(Path.Combine(reference.DirectoryName, scatterFile)); | ||
// Clone metadata. | ||
referenceItem.CopyMetadataTo(item); | ||
// We don't have a fusion name for scatter files. | ||
RemoveNonForwardableMetadata(item); | ||
|
||
// Add the satellite item. | ||
scatterItems.Add(item); | ||
|
@@ -2783,9 +2754,50 @@ private ITaskItem SetItemMetadata(List<ITaskItem> relatedItems, List<ITaskItem> | |
} | ||
} | ||
|
||
if (reference.IsWinMDFile) | ||
{ | ||
// The ImplementationAssembly is only set if the implementation file exits on disk | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Typo |
||
if (reference.ImplementationAssembly != null) | ||
{ | ||
if (VerifyArchitectureOfImplementationDll(reference.ImplementationAssembly, reference.FullPath)) | ||
{ | ||
// Add the implementation item as a related file | ||
ITaskItem item = new TaskItem(reference.ImplementationAssembly); | ||
// Clone metadata. | ||
referenceItem.CopyMetadataTo(item); | ||
|
||
// Add the related item. | ||
relatedItems.Add(item); | ||
|
||
referenceItem.SetMetadata(ItemMetadataNames.winmdImplmentationFile, Path.GetFileName(reference.ImplementationAssembly)); | ||
nonForwardableMetadata?.Remove(ItemMetadataNames.winmdImplmentationFile); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These inverted remove-from-the-removal-list things definitely need a comment please. |
||
} | ||
} | ||
|
||
nonForwardableMetadata?.Remove(ItemMetadataNames.winMDFileType); | ||
if (reference.IsManagedWinMDFile) | ||
{ | ||
referenceItem.SetMetadata(ItemMetadataNames.winMDFileType, "Managed"); | ||
} | ||
else | ||
{ | ||
referenceItem.SetMetadata(ItemMetadataNames.winMDFileType, "Native"); | ||
} | ||
nonForwardableMetadata?.Remove(ItemMetadataNames.winMDFile); | ||
referenceItem.SetMetadata(ItemMetadataNames.winMDFile, "true"); | ||
} | ||
|
||
// Set the FusionName metadata properly. | ||
referenceItem.SetMetadata(ItemMetadataNames.fusionName, fusionName); | ||
|
||
if (nonForwardableMetadata != null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment please |
||
{ | ||
foreach (KeyValuePair<string, string> kvp in nonForwardableMetadata) | ||
{ | ||
referenceItem.SetMetadata(kvp.Key, kvp.Value); | ||
} | ||
} | ||
|
||
return referenceItem; | ||
} | ||
|
||
|
@@ -2919,15 +2931,37 @@ internal static UInt16 ReadMachineTypeFromPEHeader(string dllPath) | |
/// <summary> | ||
/// Some metadata should not be forwarded between the parent and child items. | ||
/// </summary> | ||
private static void RemoveNonForwardableMetadata(ITaskItem item) | ||
private static Dictionary<string, string> RemoveNonForwardableMetadata(ITaskItem item) | ||
ladipro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
item.RemoveMetadata(ItemMetadataNames.winmdImplmentationFile); | ||
item.RemoveMetadata(ItemMetadataNames.imageRuntime); | ||
item.RemoveMetadata(ItemMetadataNames.winMDFile); | ||
Dictionary<string, string> metadata = new Dictionary<string, string>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a more descriptive name for this variable? |
||
string meta = item.GetMetadata(ItemMetadataNames.winmdImplmentationFile); | ||
if (!String.IsNullOrEmpty(meta)) | ||
{ | ||
metadata.Add(ItemMetadataNames.winmdImplmentationFile, meta); | ||
} | ||
meta = item.GetMetadata(ItemMetadataNames.imageRuntime); | ||
if (!String.IsNullOrEmpty(meta)) | ||
{ | ||
metadata.Add(ItemMetadataNames.imageRuntime, meta); | ||
} | ||
meta = item.GetMetadata(ItemMetadataNames.winMDFile); | ||
if (!String.IsNullOrEmpty(meta)) | ||
{ | ||
metadata.Add(ItemMetadataNames.winMDFile, meta); | ||
} | ||
if (!Traits.Instance.EscapeHatches.TargetPathForRelatedFiles) | ||
{ | ||
meta = item.GetMetadata(ItemMetadataNames.targetPath); | ||
if (!String.IsNullOrEmpty(meta)) | ||
{ | ||
metadata.Add(ItemMetadataNames.targetPath, meta); | ||
} | ||
item.RemoveMetadata(ItemMetadataNames.targetPath); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this one has to be next to the add to the new list, can you move the others to be next to their equivalents too? |
||
} | ||
item.RemoveMetadata(ItemMetadataNames.winmdImplmentationFile); | ||
item.RemoveMetadata(ItemMetadataNames.imageRuntime); | ||
item.RemoveMetadata(ItemMetadataNames.winMDFile); | ||
return metadata; | ||
} | ||
|
||
/// <summary> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My gut feeling is that these will all be small enough that keeping them live all at once instead of in sequence won't be a memory problem. But do you have data on that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. How would I get such data? Build OrchardCore and...somehow check whether something is being paged out?