diff options
| author | Martin Hořeňovský | 2021-05-30 13:05:07 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2021-05-30 13:06:03 +0200 |
| commit | 41ad0fda11d0898ce3aaeee9db4e7bc16eec5051 (patch) | |
| tree | df816033794fbd493cb053848d315dcc7d2b523b /src/catch2/internal/catch_xmlwriter.cpp | |
| parent | d9f72868b2662c505bad3f5d47163816573bc14a (diff) | |
| download | catch3-41ad0fda11d0898ce3aaeee9db4e7bc16eec5051.tar.gz | |
Improve XmlWriter::writeAttribute overload set for string-like types
Previously, string literals and `std::string`s would match the
template variant, which would serialize them into a stream and then
call the `StringRef` overload for resulting string. This caused
bunch of codebloat and unnecessary pessimization for common usage.
Diffstat (limited to 'src/catch2/internal/catch_xmlwriter.cpp')
| -rw-r--r-- | src/catch2/internal/catch_xmlwriter.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/catch2/internal/catch_xmlwriter.cpp b/src/catch2/internal/catch_xmlwriter.cpp index 730f1dbd..b8635f7f 100644 --- a/src/catch2/internal/catch_xmlwriter.cpp +++ b/src/catch2/internal/catch_xmlwriter.cpp @@ -217,6 +217,14 @@ namespace { return *this; } + XmlWriter::ScopedElement& + XmlWriter::ScopedElement::writeAttribute( StringRef name, + StringRef attribute ) { + m_writer->writeAttribute( name, attribute ); + return *this; + } + + XmlWriter::XmlWriter( std::ostream& os ) : m_os( os ) { writeDeclaration(); @@ -276,7 +284,13 @@ namespace { } XmlWriter& XmlWriter::writeAttribute( StringRef name, bool attribute ) { - m_os << ' ' << name << "=\"" << ( attribute ? "true" : "false" ) << '"'; + writeAttribute(name, (attribute ? "true"_sr : "false"_sr)); + return *this; + } + + XmlWriter& XmlWriter::writeAttribute( StringRef name, + char const* attribute ) { + writeAttribute( name, StringRef( attribute ) ); return *this; } |