# HG changeset patch # User dbateman # Date 1184948011 0 # Node ID f966543d105fe30b54a23aa60cde9cd391dc3355 # Parent e3f06290847c76e6ff35ada903766fd02b57d1cd [project @ 2007-07-20 16:13:31 by dbateman] diff -r e3f06290847c -r f966543d105f src/ChangeLog --- a/src/ChangeLog Fri Jul 20 16:09:01 2007 +0000 +++ b/src/ChangeLog Fri Jul 20 16:13:31 2007 +0000 @@ -1,3 +1,9 @@ +2007-07-20 David Bateman + + * zfstream.cc (BUFSIZE): Increase default buffer size to 256kB + (gzfilebuf::underflow): Stash the last 16 characters read, so as + to avoid calling pbackfail as much as possible. + 2007-07-18 David Bateman * zfstream.cc (int_type gzfilebuf::pbackfail (int_type)): New diff -r e3f06290847c -r f966543d105f src/zfstream.cc --- a/src/zfstream.cc Fri Jul 20 16:09:01 2007 +0000 +++ b/src/zfstream.cc Fri Jul 20 16:13:31 2007 +0000 @@ -40,7 +40,8 @@ #include // for BUFSIZ // Internal buffer sizes (default and "unbuffered" versions) -#define BIGBUFSIZE BUFSIZ +#define STASHED_CHARACTERS 16 +#define BIGBUFSIZE (256 * 1024 + STASHED_CHARACTERS) #define SMALLBUFSIZE 1 /*****************************************************************************/ @@ -262,9 +263,21 @@ if (!this->is_open() || !(io_mode & std::ios_base::in)) return traits_type::eof(); + // Copy the final characters to the front of the buffer + int stash = 0; + if (this->eback() && buffer && buffer_size > STASHED_CHARACTERS) + { + char_type *ptr1 = buffer; + char_type *ptr2 = this->egptr() - STASHED_CHARACTERS + 1; + if (ptr2 > this->eback()) + while (stash++ <= STASHED_CHARACTERS) + *ptr1++ = *ptr2++; + } + // Attempt to fill internal buffer from gzipped file // (buffer must be guaranteed to exist...) - int bytes_read = gzread(file, buffer, buffer_size); + int bytes_read = gzread(file, buffer + stash, buffer_size - stash); + // Indicates error or EOF if (bytes_read <= 0) { @@ -272,8 +285,8 @@ this->setg(buffer, buffer, buffer); return traits_type::eof(); } - // Make all bytes read from file available as get area - this->setg(buffer, buffer, buffer + bytes_read); + // Make all bytes read from file plus the stash available as get area + this->setg(buffer, buffer + stash, buffer + bytes_read + stash); // Return next character in get area return traits_type::to_int_type(*(this->gptr()));