Closed rasmus-z closed 2 months ago
First of all, thank you for pointing out this problem. I must have overlooked it when testing.
I have run some benchmarks between different variations on how that issue could be fixed, including your solution:
This said, LINQ doesnt perform great - it's over 4x slower and allocates about 30x more memory than a simple if-check:
foreach (char c in Path.GetInvalidFileNameChars())
if (c != '\\')
fileName = fileName.Replace(c, '_');
return fileName;
An even better solution would be to simply store an own array including all invalid filename chars except '\', which I ended up doing.
Of course this is micro-optimizing and has little to no benefit in real usage but since the function is called on every single track being downloaded I think it wouldn't hurt to make it just a little faster.
I have made a pull request on the fork with the improvements. Please accept it so I can merge it with the main repo and push an update to Melora.
Ah yes, sure might be a bit micro-optimization-y but since the optimization isn't complicated to implement nor use I definitely see it's worth. I've merged the pull request on the fork.
ToLegitFileName replaced '\' with '_'. That made folders via Filename format not work.