Skip to content

Commit

Permalink
Cache version info strings
Browse files Browse the repository at this point in the history
  • Loading branch information
mnadareski committed Dec 17, 2024
1 parent a86af8c commit ed6556b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions SabreTools.Serialization/Wrappers/PortableExecutable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,11 @@ public string? AssemblyVersion
/// </summary>
private Models.PortableExecutable.VersionInfo? _versionInfo = null;

/// <summary>
/// Cached version info strings data
/// </summary>
private readonly Dictionary<string, string?> _versionInfoStrings = [];

/// <summary>
/// Cached assembly manifest data
/// </summary>
Expand Down Expand Up @@ -842,6 +847,10 @@ public PortableExecutable(Models.PortableExecutable.Executable? model, Stream? d
if (string.IsNullOrEmpty(key))
return null;

// If we have the value cached
if (_versionInfoStrings.ContainsKey(key))
return _versionInfoStrings[key];

// Ensure that we have the resource data cached
if (ResourceData == null)
return null;
Expand All @@ -862,17 +871,22 @@ public PortableExecutable(Models.PortableExecutable.Executable? model, Stream? d
// Return the match if found
match = Array.Find(st.Children, sd => sd != null && key.Equals(sd.Key, StringComparison.OrdinalIgnoreCase));
if (match != null)
return match.Value?.TrimEnd('\0');
{
_versionInfoStrings[key] = match.Value?.TrimEnd('\0');
return _versionInfoStrings[key];
}
}

return null;
_versionInfoStrings[key] = null;
return _versionInfoStrings[key];
#else
var match = stringTable
.SelectMany(st => st?.Children ?? [])
.FirstOrDefault(sd => sd != null && key.Equals(sd.Key, StringComparison.OrdinalIgnoreCase));

// Return either the match or null
return match?.Value?.TrimEnd('\0');
_versionInfoStrings[key] = match?.Value?.TrimEnd('\0');
return _versionInfoStrings[key];
#endif
}

Expand Down

0 comments on commit ed6556b

Please sign in to comment.