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

copied strings deprecation #71

Merged

Conversation

cmazakas
Copy link
Collaborator

@cmazakas cmazakas commented Mar 7, 2024

Replace copied_strings with a dedicated helper that avoids the need for an extraneous copy. Also add an align_up() helper to be used in a few other places in the codebase eventually.

closes #59

@cmazakas cmazakas requested review from vinniefalco and ashtum March 7, 2024 18:52
char* set_prefix_impl(std::size_t);
struct prefix_holder {
message_base& mb_;
span<char> prefix_;
Copy link
Member

Choose a reason for hiding this comment

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

why span instead of string_view?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

span is used because we're going to be copying into this, i.e. it's mutable.

string_view should really only be used for const views.


message_base::
prefix_holder::
~prefix_holder() {
Copy link
Member

Choose a reason for hiding this comment

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

why do the braces keep ending up on another line instead of their own line?

char* buf_ = nullptr;
std::size_t n_ = 0;

prefix_holder(message_base& mb, std::size_t n);
Copy link
Member

Choose a reason for hiding this comment

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

noexcept?

Copy link

codecov bot commented Mar 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.09%. Comparing base (417c8b8) to head (a51b002).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #71      +/-   ##
===========================================
+ Coverage    87.84%   88.09%   +0.25%     
===========================================
  Files           77       78       +1     
  Lines         4302     4260      -42     
===========================================
- Hits          3779     3753      -26     
+ Misses         523      507      -16     
Files Coverage Δ
include/boost/http_proto/fields_base.hpp 100.00% <ø> (ø)
include/boost/http_proto/message_base.hpp 100.00% <ø> (ø)
src/detail/align_up.hpp 100.00% <100.00%> (ø)
src/detail/header.cpp 94.00% <100.00%> (-0.02%) ⬇️
src/detail/header.hpp 100.00% <100.00%> (ø)
src/message_base.cpp 77.33% <ø> (-8.02%) ⬇️
src/request.cpp 100.00% <100.00%> (ø)
src/response.cpp 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 417c8b8...a51b002. Read the comment docs.

dest,
ms.data(),
ms.size());
dest += ms.size();
*dest++ = ' ';
std::memcpy(
std::memmove(
Copy link
Member

Choose a reason for hiding this comment

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

are you sure memmove is needed instead of memcpy?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup. This is because this method is invoked with self-aliasing string_views so in this case, it's correct to use memmove.

If you switch it to memcpy, the sanitizer builds will fail with an invalid memcpy violation.

Copy link
Member

Choose a reason for hiding this comment

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

lovely

@cmazakas cmazakas force-pushed the feature/copied-strings-deprecation branch from 93499f7 to 5b6bd15 Compare March 7, 2024 23:14
@cmazakas cmazakas force-pushed the feature/copied-strings-deprecation branch from 5b6bd15 to 59137db Compare March 8, 2024 00:01
@cmazakas cmazakas force-pushed the feature/copied-strings-deprecation branch from 59137db to c799fb7 Compare March 8, 2024 17:28

prefix_op(
message_base& mb,
std::size_t n)
Copy link
Member

Choose a reason for hiding this comment

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

would noexcept help?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We shouldn't apply noexcept here because this function allocates and it also enforces a length check via detail::throw_length_error().

max_offset - h.size))
detail::throw_length_error();

auto n0 = detail::header::bytes_needed(
Copy link
Member

Choose a reason for hiding this comment

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

When I use short variable names I typically use, say "n0" to mean the old value and "n1" to mean the new value so you might think about changing this to n1.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense. Good to know, thank you.

@cmazakas cmazakas force-pushed the feature/copied-strings-deprecation branch from c799fb7 to 337ddc6 Compare March 8, 2024 18:51
@cmazakas cmazakas force-pushed the feature/copied-strings-deprecation branch from 337ddc6 to a51b002 Compare March 8, 2024 19:15
@vinniefalco
Copy link
Member

This looks good

@cmazakas cmazakas merged commit e94906b into cppalliance:develop Mar 8, 2024
53 checks passed
@cmazakas cmazakas deleted the feature/copied-strings-deprecation branch March 8, 2024 20:37
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.

Deprecate copied_strings
3 participants