mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 04:41:16 +00:00
Switched to reading the entire file into a buffer at the start.\nThis speeds it up a TON (like 100x).
This commit is contained in:
@@ -4,26 +4,39 @@
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
int Stream::pos() const
|
||||
Stream::Stream(std::istream& input): buffer(0), pos(0), line(0), column(0), size(0)
|
||||
{
|
||||
return input.tellg();
|
||||
std::streambuf *pBuf = input.rdbuf();
|
||||
|
||||
// store entire file in buffer
|
||||
size = pBuf->pubseekoff(0, std::ios::end, std::ios::in);
|
||||
pBuf->pubseekpos(0, std::ios::in);
|
||||
buffer = new char[size];
|
||||
pBuf->sgetn(buffer, size);
|
||||
}
|
||||
|
||||
|
||||
Stream::~Stream()
|
||||
{
|
||||
delete [] buffer;
|
||||
}
|
||||
|
||||
|
||||
char Stream::peek()
|
||||
{
|
||||
return input.peek();
|
||||
return buffer[pos];
|
||||
}
|
||||
|
||||
Stream::operator bool()
|
||||
Stream::operator bool() const
|
||||
{
|
||||
return input.good();
|
||||
return pos < size;
|
||||
}
|
||||
|
||||
// get
|
||||
// . Extracts a character from the stream and updates our position
|
||||
char Stream::get()
|
||||
{
|
||||
char ch = input.get();
|
||||
char ch = buffer[pos];
|
||||
pos++;
|
||||
column++;
|
||||
if(ch == '\n') {
|
||||
column = 0;
|
||||
|
Reference in New Issue
Block a user