Because formatting using c++ streams is stateful, drop down to C is required Alternatively we could use stringstream, but its performance is... not good.
| 14960 | // Because formatting using c++ streams is stateful, drop down to C is required |
| 14961 | // Alternatively we could use stringstream, but its performance is... not good. |
| 14962 | std::string getFormattedDuration( double duration ) { |
| 14963 | // Max exponent + 1 is required to represent the whole part |
| 14964 | // + 1 for decimal point |
| 14965 | // + 3 for the 3 decimal places |
| 14966 | // + 1 for null terminator |
| 14967 | const std::size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1; |
| 14968 | char buffer[maxDoubleSize]; |
| 14969 | |
| 14970 | // Save previous errno, to prevent sprintf from overwriting it |
| 14971 | ErrnoGuard guard; |
| 14972 | #ifdef _MSC_VER |
| 14973 | sprintf_s(buffer, "%.3f", duration); |
| 14974 | #else |
| 14975 | std::sprintf(buffer, "%.3f", duration); |
| 14976 | #endif |
| 14977 | return std::string(buffer); |
| 14978 | } |
| 14979 | |
| 14980 | std::string serializeFilters( std::vector<std::string> const& container ) { |
| 14981 | ReusableStringStream oss; |
no test coverage detected