small improvments

This commit is contained in:
gabime 2014-05-11 03:33:33 +03:00
parent 0948a1257d
commit 3d5ee3ff56

View File

@ -1,6 +1,8 @@
#pragma once #pragma once
// Faster than ostringstream--returns its string by ref // A faster-than-ostringstream class
// uses stack_buf as the underlying buffer (upto 192 bytes before using the heap)
#include <ostream> #include <ostream>
#include "stack_buf.h" #include "stack_buf.h"
@ -9,12 +11,12 @@ namespace c11log
namespace details namespace details
{ {
class stack_devicebuf :public std::streambuf class stack_devicebuf :public std::streambuf
{ {
public: public:
using Base = std::streambuf; static constexpr unsigned short stack_size = 192;
using stackbuf = stack_buf<192>; using stackbuf_t = stack_buf<stack_size>;
stack_devicebuf() = default; stack_devicebuf() = default;
~stack_devicebuf() = default; ~stack_devicebuf() = default;
stack_devicebuf& operator=(const stack_devicebuf&) = delete; stack_devicebuf& operator=(const stack_devicebuf&) = delete;
@ -29,7 +31,7 @@ public:
other.clear(); other.clear();
} }
stackbuf::bufpair_t buf() const stackbuf_t::bufpair_t buf() const
{ {
return _stackbuf.get(); return _stackbuf.get();
} }
@ -62,9 +64,10 @@ protected:
return ch; return ch;
} }
private: private:
stackbuf _stackbuf; stackbuf_t _stackbuf;
}; };
class fast_oss :public std::ostream class fast_oss :public std::ostream
{ {
public: public:
@ -82,7 +85,6 @@ public:
other.clear(); other.clear();
} }
std::string str() std::string str()
{ {
auto buf = _dev.buf(); auto buf = _dev.buf();
@ -90,7 +92,6 @@ public:
} }
std::size_t size() const std::size_t size() const
{ {
return _dev.size(); return _dev.size();