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

Microsoft Windows std.stdio.File.lock(), tryLock(), unlock(): do not allocate memory for error messages when they are not needed #7740

Merged
merged 1 commit into from
Jan 4, 2021

Conversation

n8sh
Copy link
Member

@n8sh n8sh commented Jan 4, 2021

No description provided.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @n8sh!

Bugzilla references

Auto-close Bugzilla Severity Description
21523 enhancement Microsoft Windows std.stdio.File.lock(), tryLock(), unlock(): do not allocate memory for error messages when they are not needed

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + phobos#7740"

@CyberShadow
Copy link
Member

Why not just make the wenforce argument lazy?

@n8sh
Copy link
Member Author

n8sh commented Jan 4, 2021

Because I wanted to be able to add pragma(inline, false) and have it only affect the cold path. In your opinion was the other way better?

@CyberShadow
Copy link
Member

CyberShadow commented Jan 4, 2021

From a code readability standpoint, enforce variants are better than explicit if constructs. if being a control flow structure should be used for important aspects of the function's algorithm, but when it's used for trivial error handling, it becomes a distraction.

lazy would put the code constructing the error message string into its own function (implicit lambda), so that should achieve something similar, right?

In any case, optimizing without benchmarking is usually not practical, and optimizing CPU for functions doing I/O is usually not very impactful.

Edit: FWIW, std.exception.enforce has its message argument as lazy, so going that way would be consistent with it.

… unlock(): do not allocate memory for error messages when they are not needed
@n8sh
Copy link
Member Author

n8sh commented Jan 4, 2021

I have made the suggested change.

@CyberShadow
Copy link
Member

Thanks!

@dlang-bot dlang-bot merged commit c16bb67 into dlang:master Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants