Make StringRef's operator std::string explicit
This way it is explicit when there is a `StringRef` -> `std::string` conversion and makes it easier to look for allocations that could be avoided. Doing this has already removed one allocation per registered test case, as there was a completely pointless `StringRef` -> `std::string` conversion when parsing tags of a test case.
This commit is contained in:
parent
14362533bb
commit
7b865daccc
13 changed files with 23 additions and 67 deletions
|
@ -23,6 +23,7 @@ namespace Catch {
|
|||
class StringRef {
|
||||
public:
|
||||
using size_type = std::size_t;
|
||||
using const_iterator = const char*;
|
||||
|
||||
private:
|
||||
friend struct StringRefTestAccess;
|
||||
|
@ -78,7 +79,7 @@ namespace Catch {
|
|||
return *this;
|
||||
}
|
||||
|
||||
operator std::string() const;
|
||||
explicit operator std::string() const;
|
||||
|
||||
void swap( StringRef& other ) noexcept;
|
||||
|
||||
|
@ -105,6 +106,10 @@ namespace Catch {
|
|||
// Note that the pointer can change when if the StringRef is a substring
|
||||
auto currentData() const noexcept -> char const*;
|
||||
|
||||
public: // iterators
|
||||
const_iterator begin() const { return m_start; }
|
||||
const_iterator end() const { return m_start + m_size; }
|
||||
|
||||
private: // ownership queries - may not be consistent between calls
|
||||
auto isOwned() const noexcept -> bool;
|
||||
auto isSubstring() const noexcept -> bool;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue