mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 05:16:10 +01:00
Use StringRef for Opt's optNames
Removes another ~70 allocations.
This commit is contained in:
parent
5d5f42f99b
commit
cd3c7ebe87
@ -25,13 +25,16 @@ namespace {
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string normaliseOpt( std::string const& optName ) {
|
Catch::StringRef normaliseOpt( Catch::StringRef optName ) {
|
||||||
#ifdef CATCH_PLATFORM_WINDOWS
|
if ( optName[0] == '-'
|
||||||
if ( optName[0] == '/' )
|
#if defined(CATCH_PLATFORM_WINDOWS)
|
||||||
return "-" + optName.substr( 1 );
|
|| optName[0] == '/'
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
return optName;
|
) {
|
||||||
|
return optName.substr( 1, optName.size() );
|
||||||
|
}
|
||||||
|
|
||||||
|
return optName;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -545,7 +545,7 @@ namespace Catch {
|
|||||||
// A parser for options
|
// A parser for options
|
||||||
class Opt : public Detail::ParserRefImpl<Opt> {
|
class Opt : public Detail::ParserRefImpl<Opt> {
|
||||||
protected:
|
protected:
|
||||||
std::vector<std::string> m_optNames;
|
std::vector<StringRef> m_optNames;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
template <typename LambdaT>
|
template <typename LambdaT>
|
||||||
@ -571,11 +571,11 @@ namespace Catch {
|
|||||||
Opt( T& ref, StringRef hint ):
|
Opt( T& ref, StringRef hint ):
|
||||||
ParserRefImpl( ref, hint ) {}
|
ParserRefImpl( ref, hint ) {}
|
||||||
|
|
||||||
Opt& operator[]( std::string const& optName ) & {
|
Opt& operator[]( StringRef optName ) & {
|
||||||
m_optNames.push_back(optName);
|
m_optNames.push_back(optName);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
Opt&& operator[]( std::string const& optName ) && {
|
Opt&& operator[]( StringRef optName ) && {
|
||||||
m_optNames.push_back( optName );
|
m_optNames.push_back( optName );
|
||||||
return CATCH_MOVE(*this);
|
return CATCH_MOVE(*this);
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns a substring of [start, start + length).
|
// Returns a substring of [start, start + length).
|
||||||
// If start + length > size(), then the substring is [start, start + size()).
|
// If start + length > size(), then the substring is [start, size()).
|
||||||
// If start > size(), then the substring is empty.
|
// If start > size(), then the substring is empty.
|
||||||
constexpr StringRef substr(size_type start, size_type length) const noexcept {
|
constexpr StringRef substr(size_type start, size_type length) const noexcept {
|
||||||
if (start < m_size) {
|
if (start < m_size) {
|
||||||
|
Loading…
Reference in New Issue
Block a user