|
|
@ -2,8 +2,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
// Faster than ostringstream--returns its string by ref
|
|
|
|
// Faster than ostringstream--returns its string by ref
|
|
|
|
|
|
|
|
|
|
|
|
#include<streambuf>
|
|
|
|
#include "c11log/details/fast_buf.h"
|
|
|
|
#include<string>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace c11log
|
|
|
|
namespace c11log
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -21,15 +20,21 @@ public:
|
|
|
|
str_devicebuf& operator=(const str_devicebuf&) = delete;
|
|
|
|
str_devicebuf& operator=(const str_devicebuf&) = delete;
|
|
|
|
str_devicebuf& operator=(str_devicebuf&&) = delete;
|
|
|
|
str_devicebuf& operator=(str_devicebuf&&) = delete;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
const std::string& str_ref() const
|
|
|
|
const std::string& str_ref() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return _str;
|
|
|
|
return _str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
bufpair_t buf()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return _fastbuf.get();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void reset_str()
|
|
|
|
void reset_str()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_str.clear();
|
|
|
|
//_str.clear();
|
|
|
|
|
|
|
|
_fastbuf.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
protected:
|
|
|
@ -42,11 +47,14 @@ protected:
|
|
|
|
// reserve initially 128 bytes which should be enough for common log lines
|
|
|
|
// reserve initially 128 bytes which should be enough for common log lines
|
|
|
|
std::streamsize xsputn(const char_type* s, std::streamsize count) override
|
|
|
|
std::streamsize xsputn(const char_type* s, std::streamsize count) override
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
if(_str.capacity() < k_initial_reserve)
|
|
|
|
if(_str.capacity() < k_initial_reserve)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_str.reserve(k_initial_reserve);
|
|
|
|
_str.reserve(k_initial_reserve);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_str.append(s, static_cast<unsigned int>(count));
|
|
|
|
_str.append(s, static_cast<unsigned int>(count));
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
_fastbuf.append(s, static_cast<unsigned int>(count));
|
|
|
|
return count;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -62,8 +70,8 @@ protected:
|
|
|
|
return not_eofile;
|
|
|
|
return not_eofile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
std::string _str;
|
|
|
|
//std::string _str;
|
|
|
|
static constexpr std::streamsize k_initial_reserve = 128;
|
|
|
|
fast_buf<128> _fastbuf;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class fast_oss:public std::ostream
|
|
|
|
class fast_oss:public std::ostream
|
|
|
@ -75,11 +83,17 @@ public:
|
|
|
|
fast_oss(const fast_oss& other) = delete;
|
|
|
|
fast_oss(const fast_oss& other) = delete;
|
|
|
|
fast_oss(fast_oss&& other) = delete;
|
|
|
|
fast_oss(fast_oss&& other) = delete;
|
|
|
|
fast_oss& operator=(const fast_oss& other) = delete;
|
|
|
|
fast_oss& operator=(const fast_oss& other) = delete;
|
|
|
|
|
|
|
|
/*
|
|
|
|
const std::string& str_ref() const
|
|
|
|
const std::string& str_ref() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return _dev.str_ref();
|
|
|
|
return _dev.str_ref();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
bufpair_t buf()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return _dev.buf();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void reset_str()
|
|
|
|
void reset_str()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_dev.reset_str();
|
|
|
|
_dev.reset_str();
|
|
|
|