-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #361, "Memory error when moving a cse::uri"
I've replaced the internal `std::string_view` members in `cse::uri` with a new type (`subrange`) which is independent of absolute memory location but otherwise contains the same information. To be able to take advantage of all the nice functionality built into `std::string_view`, `subrange` is only used for storage, not for processing.
- Loading branch information
1 parent
98a3fe2
commit 79c81ef
Showing
3 changed files
with
151 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,45 @@ BOOST_AUTO_TEST_CASE(uri_parser) | |
} | ||
|
||
|
||
BOOST_AUTO_TEST_CASE(uri_copy_and_move) | ||
{ | ||
auto orig = uri("http://[email protected]:1234/foo/bar?q=uux#frag"); | ||
const auto copy = orig; | ||
const auto move = std::move(orig); | ||
orig = uri(); | ||
|
||
BOOST_REQUIRE(copy.scheme().has_value()); | ||
BOOST_TEST(*copy.scheme() == "http"); | ||
BOOST_REQUIRE(copy.authority().has_value()); | ||
BOOST_TEST(*copy.authority() == "[email protected]:1234"); | ||
BOOST_TEST(copy.path() == "/foo/bar"); | ||
BOOST_REQUIRE(copy.query().has_value()); | ||
BOOST_TEST(*copy.query() == "q=uux"); | ||
BOOST_REQUIRE(copy.fragment().has_value()); | ||
BOOST_TEST(*copy.fragment() == "frag"); | ||
|
||
BOOST_REQUIRE(move.scheme().has_value()); | ||
BOOST_TEST(*move.scheme() == "http"); | ||
BOOST_REQUIRE(move.authority().has_value()); | ||
BOOST_TEST(*move.authority() == "[email protected]:1234"); | ||
BOOST_TEST(move.path() == "/foo/bar"); | ||
BOOST_REQUIRE(move.query().has_value()); | ||
BOOST_TEST(*move.query() == "q=uux"); | ||
BOOST_REQUIRE(move.fragment().has_value()); | ||
BOOST_TEST(*move.fragment() == "frag"); | ||
|
||
// Special case: Short strings which may be affected by the small-string | ||
// optimisation (see issue #361) | ||
auto small = uri("x"); | ||
const auto smallCopy = small; | ||
const auto smallMove = std::move(small); | ||
small = uri(); | ||
|
||
BOOST_TEST(smallCopy.path() == "x"); | ||
BOOST_TEST(smallMove.path() == "x"); | ||
} | ||
|
||
|
||
BOOST_AUTO_TEST_CASE(uri_comparison) | ||
{ | ||
const auto httpURI = uri("http://[email protected]:1234/foo/bar?q=uux#frag"); | ||
|