diff options
author | Brian Silverman <brian@peloton-tech.com> | 2016-07-19 23:44:26 (GMT) |
---|---|---|
committer | Brian Silverman <brian@peloton-tech.com> | 2017-08-28 20:00:48 (GMT) |
commit | 4d26df729c4172a4786fb4ca509a264dfd9b89dc (patch) | |
tree | 9174c7fead726638709296f2676f2321b44c14b4 /googletest/src | |
parent | b43bfcf49166599955ba3713952bc6c0e96b421b (diff) | |
download | googletest-4d26df729c4172a4786fb4ca509a264dfd9b89dc.zip googletest-4d26df729c4172a4786fb4ca509a264dfd9b89dc.tar.gz googletest-4d26df729c4172a4786fb4ca509a264dfd9b89dc.tar.bz2 |
Speed up printing of characters which need hex escaping
This change speeds up the runtime of a value-parameterized test I have
which has lots of values with large strings full of unprintable
characters by 2x. I profiled it and traced most of the slowness during
googletest startup down to the way String::FormatHexInt was creating and
destroyed a stringstream for each character in the string for each
value.
Diffstat (limited to 'googletest/src')
-rw-r--r-- | googletest/src/gtest-printers.cc | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/googletest/src/gtest-printers.cc b/googletest/src/gtest-printers.cc index a2df412..dd67f64 100644 --- a/googletest/src/gtest-printers.cc +++ b/googletest/src/gtest-printers.cc @@ -180,7 +180,10 @@ static CharFormat PrintAsCharLiteralTo(Char c, ostream* os) { *os << static_cast<char>(c); return kAsIs; } else { - *os << "\\x" + String::FormatHexInt(static_cast<UnsignedChar>(c)); + ostream::fmtflags flags = os->flags(); + *os << "\\x" << std::hex << std::uppercase + << static_cast<int>(static_cast<UnsignedChar>(c)); + os->flags(flags); return kHexEscape; } } |