-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Efficient Access To basic_stringbuf's Buffer #919
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
Conversation
There're two questions I cannot decide:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I have some initial comments after reviewing all of the files (although I haven't done a line-by-line comparison of the product code to the Standardese yet).
tests/std/tests/P0408R7_efficient_access_to_stringbuf_buffer/env.lst
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I have a number of comments but the issues I found were localized - to save time, I will work on fixing them later today.
#if _HAS_CXX20 | ||
template <class _Ty> | ||
concept _Allocator = _Is_allocator<_Ty>::value; | ||
#endif // _HAS_CXX20 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks OK to me. I think the unusual part is that this is actually a concept
. Elsewhere, we've used SFINAE to implement constraints in C++20 features, except when concepts are absolutely unavoidable (for example <ranges>
; also <span>
has a conformant concepts and fallback SFINAE implementation). This is because EDG has certain bugs that prevent us from fully enabling concepts at this time.
Given that the tests are passing, and that we ultimately do want to use concepts in C++20 mode, I think this is OK. If we encounter issues with EDG, replacing this concept with SFINAE should be a targeted change.
Separately, it would be possible to implement this concept "directly" instead of by referring to the SFINAE implementation that I wrote for CTAD; however I am not sure that there are any throughput benefits to doing so, and duplicating that somewhat complicated definition would be undesirable, so the centralized approach seems ideal.
_Construct_in_place(_My_data._Bx._Ptr, _Fancy_right); | ||
return true; | ||
} else { | ||
_Traits::copy(_My_data._Bx._Buf, _Right, _Res); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am unsure whether we should copy _Res
characters, or _Size + 1
for just the characters that are actually stored (+ 1
for the null terminator).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a correctness issue, so I don't want to risk damaging the code. No change requested.
} else { | ||
// use _BUF_SIZE + 1 to avoid SSO, if the buffer is assigned back | ||
_Result._Ptr = _Al.allocate(_BUF_SIZE + 1); | ||
_Traits::copy(_Unfancy(_Result._Ptr), _My_data._Bx._Buf, _BUF_SIZE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, I am unsure whether we should copy the entire _BUF_SIZE
, or just _My_data._Mysize + 1
for the actually stored characters plus the null terminator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto no change requested.
tests/std/tests/P0408R7_efficient_access_to_stringbuf_buffer/test.cpp
Outdated
Show resolved
Hide resolved
tests/std/tests/P0408R7_efficient_access_to_stringbuf_buffer/test.cpp
Outdated
Show resolved
Hide resolved
For basic_istringstream/basic_ostringstream, this fixes correctness. For basic_stringstream, this improves clarity and debug codegen.
I think the review request to @BillyONeal was a mishandling by myself, but I don't know how to cancel it. |
@Berrysoft No problem, it won’t block merging. I plan to get a quick double-check from another maintainer tomorrow, then prepare an internal MSVC-PR port. |
Merged! Thanks again for implementing this feature, which will ship in VS 2019 16.10 Preview 1. 🚀 😺 🎉 |
Fixes #15