Because formatting using c++ streams is stateful, drop down to C is required Alternatively we could use stringstream, but its performance is... not good.
| 15437 | // Because formatting using c++ streams is stateful, drop down to C is required |
| 15438 | // Alternatively we could use stringstream, but its performance is... not good. |
| 15439 | std::string getFormattedDuration( double duration ) { |
| 15440 | // Max exponent + 1 is required to represent the whole part |
| 15441 | // + 1 for decimal point |
| 15442 | // + 3 for the 3 decimal places |
| 15443 | // + 1 for null terminator |
| 15444 | const std::size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1; |
| 15445 | char buffer[maxDoubleSize]; |
| 15446 | |
| 15447 | // Save previous errno, to prevent sprintf from overwriting it |
| 15448 | ErrnoGuard guard; |
| 15449 | #ifdef _MSC_VER |
| 15450 | sprintf_s(buffer, "%.3f", duration); |
| 15451 | #else |
| 15452 | std::sprintf(buffer, "%.3f", duration); |
| 15453 | #endif |
| 15454 | return std::string(buffer); |
| 15455 | } |
| 15456 | |
| 15457 | std::string serializeFilters( std::vector<std::string> const& container ) { |
| 15458 | ReusableStringStream oss; |