Skip to content

Use =default for constructors and operator= where possible#179

Merged
etr merged 8 commits into
etr:masterfrom
bcsgh:master
Feb 26, 2020
Merged

Use =default for constructors and operator= where possible#179
etr merged 8 commits into
etr:masterfrom
bcsgh:master

Conversation

@bcsgh

@bcsgh bcsgh commented Feb 24, 2020

Copy link
Copy Markdown
Contributor

Identify the Bug

#177 (General code style issues)

Description of the Change

Use =default for constructors and operator= where possible.

For default construction, this moves the default values to a default member initializer:
https://en.cppreference.com/w/cpp/language/data_members#Member_initialization

This significantly reduce the size of code in a number of places. It also avoids the need to ensure that the list of copied/moved fields matches the list of existing fields (in some case it did not).

Possible Drawbacks

This removes the "effectively unused" protected member http_response::content. If any client code references that, this will break it.

Verification Process

./bootstrap 
mkdir build
cd build
CPPFLAGS=-I${libmicrohttpd_include} LDFLAGS=-L${libmicrohttpd_libs} ../configure
make

Release Notes

Use =default for constructors and operator= where possible.

@codecov-io

codecov-io commented Feb 24, 2020

Copy link
Copy Markdown

Codecov Report

Merging #179 into master will decrease coverage by 0.12%.
The diff coverage is 80%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #179      +/-   ##
==========================================
- Coverage   95.31%   95.19%   -0.13%     
==========================================
  Files          35       35              
  Lines        3224     3140      -84     
==========================================
- Hits         3073     2989      -84     
  Misses        151      151
Impacted Files Coverage Δ
src/httpserver/http_request.hpp 92.3% <ø> (-0.55%) ⬇️
src/httpserver/string_response.hpp 66.66% <0%> (+26.66%) ⬆️
src/httpserver/details/modded_request.hpp 100% <100%> (ø) ⬆️
src/httpserver/http_resource.hpp 33.33% <100%> (-7.85%) ⬇️
src/httpserver/basic_auth_fail_response.hpp 100% <100%> (ø) ⬆️
src/httpserver/digest_auth_fail_response.hpp 100% <100%> (ø) ⬆️
src/httpserver/file_response.hpp 100% <100%> (ø) ⬆️
src/httpserver/deferred_response.hpp 100% <100%> (ø) ⬆️
src/httpserver/create_webserver.hpp 100% <100%> (ø) ⬆️
src/httpserver/http_response.hpp 80% <50%> (+13.33%) ⬆️
... and 4 more

Continue to review full report at Codecov.

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

@bcsgh

bcsgh commented Feb 24, 2020

Copy link
Copy Markdown
Contributor Author

Apologies for fixing the noexcept issue piecemeal; I have yet to figure out how to reproduce it in a local build. (What I would give for everything to use a fully hermetic build system?!)

@bcsgh

bcsgh commented Feb 24, 2020

Copy link
Copy Markdown
Contributor Author

Note

Given that this PR consist mostly of removing code, I suspect the coverage numbers are not meaningful. Also, the delta is of a nature where most possibilities for failure are compile time issues and as such will be detected regardless of if the tests cases cover them.

@etr etr left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Not worried about the reduction in coverage as it is just the effect of the change in proportion between code ignored/considered by the metric.

Comment thread src/httpserver/http_response.hpp Outdated
std::map<std::string, std::string, http::header_comparator> cookies;

friend std::ostream &operator<< (std::ostream &os, const http_response &r);
friend std::ostream &operator<< (std::ostream &os, const http_response &r);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

the indentation must have accidentally changed here. Can we fix it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reverted.

Comment thread src/httpserver/create_webserver.hpp Outdated
size_t _content_size_limit = std::numeric_limits<size_t>::max();
int _connection_timeout = DEFAULT_WS_TIMEOUT;
int _per_IP_connection_limit = 0;
log_access_ptr _log_access = nullptr;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

As there are many comparisons of these values to 0x0, I'd isolate the change to nullptr from this change. At least we keep the change dedicated to only moving to default constructor.

Also, despite nullptr is 0x0 under the hood, but formally I'd rather have that consistent before changing it as it should act as an abstraction (so I'd rather not assume it is).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reverted.

Comment thread src/httpserver/create_webserver.hpp Outdated
int _max_threads = 0;
int _max_connections = 0;
int _memory_limit = 0;
size_t _content_size_limit = std::numeric_limits<size_t>::max();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The change from 0 to max is definitely a correct change, but I'd rather do it in a different CR to push before pushing this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Mind if I do it after this one?

(Git seems to be gratuitously obtuse when it comes to dealing with merges and PRs.)

@etr

etr commented Feb 26, 2020

Copy link
Copy Markdown
Owner

The change looks good. There have been some uncorrelated failures on Travis (they were having problems at connecting to PPA). I am restarting those to make sure nothing happens there and approving this change.

@etr
etr merged commit 9cdc901 into etr:master Feb 26, 2020
@etr

etr commented Feb 26, 2020

Copy link
Copy Markdown
Owner

Merged. Thanks for all the work and support.

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