Because formatting using c++ streams is stateful, drop down to C is required Alternatively we could use stringstream, but its performance is... not good.
| 13041 | // Because formatting using c++ streams is stateful, drop down to C is required |
| 13042 | // Alternatively we could use stringstream, but its performance is... not good. |
| 13043 | std::string getFormattedDuration( double duration ) { |
| 13044 | // Max exponent + 1 is required to represent the whole part |
| 13045 | // + 1 for decimal point |
| 13046 | // + 3 for the 3 decimal places |
| 13047 | // + 1 for null terminator |
| 13048 | const std::size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1; |
| 13049 | char buffer[maxDoubleSize]; |
| 13050 | |
| 13051 | // Save previous errno, to prevent sprintf from overwriting it |
| 13052 | ErrnoGuard guard; |
| 13053 | #ifdef _MSC_VER |
| 13054 | sprintf_s(buffer, "%.3f", duration); |
| 13055 | #else |
| 13056 | std::sprintf(buffer, "%.3f", duration); |
| 13057 | #endif |
| 13058 | return std::string(buffer); |
| 13059 | } |
| 13060 | |
| 13061 | std::string serializeFilters( std::vector<std::string> const& container ) { |
| 13062 | ReusableStringStream oss; |