-
Notifications
You must be signed in to change notification settings - Fork 241
Simplify implementation for ImageTagSet equality #1116
base: main
Are you sure you want to change the base?
Conversation
We're targeting netstandard2.0 and don't have ReadOnlySpan or any of the new APIs that avoid allocating
4bd008c
to
25cb1aa
Compare
We cache the ImageTagSet directly now. That should allow us to create fewer of these instances overall. For the app I'm testing on, we cover 97% of the image tags combinations In practice, cache hits will be better overall. The other improvement is to not have to sort/create imagetagsets every time, instead opting to use more specialized APIs.
c63203a
to
1557d48
Compare
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.
Nice!
These tag items amount for 97% of the image tags found in images. | ||
*/ | ||
readonly string[] knownTags = new[] { | ||
"dark", |
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.
I don't know why I made the cache this way. Looking back, I think that we can store the original tags
string and cache the ImageTagSet.
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.
Basically, we can have some presets, but cache tags that are added later as well.
|
||
public ImageTagSet TryGetTagSet(string tags) | ||
{ | ||
var index = Array.IndexOf(knownTags, tags); |
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.
Change to a list, and cache any tagset that isn't in the list already.
@@ -1183,16 +1184,22 @@ public override object LoadImage (string fileName) | |||
|
|||
public override IEnumerable<string> GetAlternativeFiles (string fileName, string baseName, string ext) | |||
{ | |||
if (!Context.RegisteredStyles.Any ()) { |
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.
This check breaks my brain. I don't really understand why it is !Context.RegisteredStyles.Any()
No description provided.