8000 make filesystem-accessing `FileOps` functions take `const string &` by froydnj · Pull Request #6531 · sorbet/sorbet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

make filesystem-accessing FileOps functions take const string & #6531

8000
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

Merged
merged 14 commits into from
Nov 2, 2022

Conversation

froydnj
Copy link
Contributor
@froydnj froydnj commented Nov 2, 2022

Motivation

Most of these functions take string_view, but we need to pass null-terminated strings to the underlying OS functions and therefore need to allocate a string. But in the common case, the caller already had a string, so we wind up allocating a string inside these functions for no good reason. This is probably not a big deal, but less work is less work, and we avoid weird cases like repeatedly allocating strings in e.g. FileOps::writeIfDifferent.

In cases where the caller had a string_view (which is not that many), I think allocating the string at the callsite is a good thing, or at least not a bad one. (Actually, for a lot of these, core::File::path() should be returning a const string &, and that would fix some awkwardness in places. Next PR!)

Test plan

See included automated tests.

@froydnj froydnj requested a review from a team as a code owner November 2, 2022 13:19
@froydnj froydnj requested review from jez and removed request for a team November 2, 2022 13:19
@froydnj froydnj force-pushed the froydnj-stringify-fileops branch from e5745f0 to b31441c Compare November 2, 2022 17:43
@froydnj froydnj enabled auto-merge (squash) November 2, 2022 18:19
@froydnj froydnj merged commit ce8dc56 into master Nov 2, 2022
@froydnj froydnj deleted the froydnj-stringify-fileops branch November 2, 2022 18:22
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
0