Skip to content

Commit

Permalink
Simplifying attribute value cache
Browse files Browse the repository at this point in the history
  • Loading branch information
BenedekFarkas committed Dec 7, 2024
1 parent 5185ed0 commit 3ca230d
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public class MediaProcessingHtmlFilter : IHtmlFilter {
private MediaHtmlFilterSettingsPart _settingsPart;
private static readonly Regex _imageTagRegex = new Regex(@"<img\b[^>]*>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static readonly ConcurrentDictionary<string, Regex> _attributeRegexes = new ConcurrentDictionary<string, Regex>();
private static readonly ConcurrentDictionary<string, ConcurrentDictionary<string, string>> _attributeValues =
new ConcurrentDictionary<string, ConcurrentDictionary<string, string>>();
private static readonly ConcurrentDictionary<string, string> _attributeValues = new ConcurrentDictionary<string, string>();
private static readonly Dictionary<string, string> _validExtensions = new Dictionary<string, string> {
{ ".jpeg", "jpg" }, // For example: .jpeg supports compression (quality), format to 'jpg'.
{ ".jpg", "jpg" },
Expand Down Expand Up @@ -177,8 +176,7 @@ private string ProcessImageAltContent(string imgTag) {

private string GetAttributeValue(string tag, string attributeName) =>
_attributeValues
.GetOrAdd(tag, _ => new ConcurrentDictionary<string, string>())
.GetOrAdd(attributeName, _ => {
.GetOrAdd($"{tag}_{attributeName}", _ => {
var match = GetAttributeRegex(attributeName).Match(tag);
return match.Success ? match.Groups[1].Value : null;
});
Expand Down

0 comments on commit 3ca230d

Please sign in to comment.