Skip to content
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

Improve sanitize_filename #321

Merged
merged 1 commit into from
Jan 24, 2022
Merged

Conversation

neumannt
Copy link
Contributor

The old sanitize_filename implementation copied the string unconditionally, and then did multiple passes over the string to detect Windows special device files. This implementation now keeps the string in place and finds all special devices in a single pass.

The separate commit for catch.hpp is required to build Crown on Ubuntu 21.10, MINSIGSTKSZ is not a constexpr but calls sysconf. This mimics what upstream catch2 does, an alternative would be to update the catch2 header to the latest upstream release.

@The-EDev
Copy link
Member

Thank you for your work. I haven't inspected the code thoroughly enough (Including speed tests). but from skimming it, it definitely seems like a significant improvement over the function introduced in #317.

Regarding your second commit, I would much prefer if Catch2 was updated rather than modified, if you want to open a PR for that feel free to, otherwise I'll do it after the weekend.

Thanks again for the work you've done!

@neumannt
Copy link
Contributor Author

I have dropped to catch2 patch, the issue is fixed by updating catch2 to v2.13.8.

The old implementation allocated a new string for every invocation, and
repeatedly scanned the string for occurences of the various Windows device
names. This commits resizes the original string instead if needed, and
detects all devices with a single pass.
Copy link
Member

@The-EDev The-EDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The speed test I ran showed that for the test string this function was at least 140 times faster than the previous implementation in #317, taking a maximum of 7µs.

Aside from the suggestion below, everything seems to be in order.

include/crow/utility.h Show resolved Hide resolved
@The-EDev The-EDev merged commit c5d4fe4 into CrowCpp:master Jan 24, 2022
@neumannt neumannt deleted the sanitize_filename branch January 24, 2022 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants