8000 atf-check.cpp: remove unneeded copying into vector (take 2) by ngie-eign · Pull Request #91 · freebsd/atf · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

atf-check.cpp: remove unneeded copying into vector (take 2) #91

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 1 commit into from
Dec 29, 2024

Conversation

ngie-eign
Copy link
Contributor
@ngie-eign ngie-eign commented Dec 26, 2024

This PR reintroduces the changes originally introduced in #89, which needed to be reverted due to a compiler error. See #89 (comment) and #90 for more details.

atf::fs::path has a str() method, and it returns a std::string
constructor. I found this odd that a vector is used here to copy
std::string contents. As std::string is a typedef of
std::basic_string<char>, this additional copy is not needed.

Also, remove calling the str() method on error.

Notes by ngie@:

`buf.data()` returns `const char*` until C++17, so it can't be used in
combination with `mkstemp(..)` (it mutates the template argument).
Access the internal buffer with the `operator[]` instead.

Add the C++17+ form as well along with a TODO comment, so the code can
move to std::string::data eventually.

Co-authored by:	Enji Cooper <ngie@FreeBSD.org>
Signed-off-by: rilysh <nightquick@proton.me>
@ngie-eign ngie-eign merged commit b5d484d into freebsd:master Dec 29, 2024
@ngie-eign ngie-eign deleted the reintroduce-pr-89 branch December 29, 2024 20:12
ngie-eign added a commit that referenced this pull request Mar 29, 2025
atf::fs::path has a str() method, and it returns a std::string
constructor. I found this odd that a vector is used here to copy
std::string contents. As std::string is a typedef of
std::basic_string<char>, this additional copy is not needed.

Also, remove calling the str() method on error.

Notes by ngie@:

`buf.data()` returns `const char*` until C++17, so it can't be used in
combination with `mkstemp(..)` (it mutates the template argument).
Access the internal buffer with the `operator[]` instead.

Add the C++17+ form as well along with a TODO comment, so the code can
move to std::string::data eventually.

Co-authored by:	Enji Cooper <ngie@FreeBSD.org>

Signed-off-by: rilysh <nightquick@proton.me>
Co-authored-by: rilysh <nightquick@proton.me>
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.

3 participants
0