remode stack_oss

This commit is contained in:
gabime
2014-05-08 02:23:07 +03:00
parent b72098101e
commit bafea6a6b2
13 changed files with 94 additions and 279 deletions

View File

@@ -7,10 +7,10 @@
#include <iomanip>
#include <thread>
#include <cstring>
#include <sstream>
#include "common_types.h"
#include "details/os.h"
#include "details/stack_oss.h"
namespace c11log
{
@@ -57,8 +57,7 @@ inline void c11log::formatters::default_formatter::_format_time(const log_clock:
__declspec(thread) static size_t s_cache_size;
__declspec(thread) static std::time_t s_cache_time_t = 0;
#else
thread_local static char s_cache_str[64];
thread_local static size_t s_cache_size;
thread_local static std::string s_cache_timestr;
thread_local static std::time_t s_cache_time_t = 0;
#endif
@@ -67,7 +66,7 @@ inline void c11log::formatters::default_formatter::_format_time(const log_clock:
if(tp_time_t != s_cache_time_t)
{
auto tm_now = details::os::localtime(tp_time_t);
details::stack_oss time_oss;
std::ostringstream time_oss;
time_oss.fill('0');
time_oss << '[' << tm_now.tm_year + 1900 << '-';
time_oss.width(2);
@@ -82,10 +81,10 @@ inline void c11log::formatters::default_formatter::_format_time(const log_clock:
time_oss << tm_now.tm_sec << ']';
//Cache the resulted string and its size
s_cache_time_t = tp_time_t;
//const std::string &s = time_oss.str_ref();
bufpair_t buf = time_oss.buf();
std::memcpy(s_cache_str, buf.first, buf.second);
s_cache_size = buf.second;
//const std::string &s = time_oss.str_ref();
s_cache_timestr = time_oss.str();
}
output.write(s_cache_str, s_cache_size);
output << s_cache_timestr;
}