This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: PATCH: Avoid excessive flushing on lower-layer handle
- From: Jason Merrill <jason at redhat dot com>
- To: rittle at labs dot mot dot com
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Tue, 23 Apr 2002 09:40:26 +0100
- Subject: Re: PATCH: Avoid excessive flushing on lower-layer handle
- References: <200204230545.g3N5jFK55291@latour.rsch.comm.mot.com>
>>>>> "Loren" == Loren James Rittle <rittle@latour.rsch.comm.mot.com> writes:
> // Make sure that the internal buffer resyncs its idea of
> // the file position with the external file.
> ! if (__testput)
> {
> // Need to restore current position after the write.
> off_type __off = _M_out_cur - _M_out_end;
> ! _M_really_overflow(); // _M_file.sync() will be called within
> if (__off)
> _M_file.seekoff(__off, ios_base::cur);
> }
> + else
> + _M_file.sync();
Shouldn't this be unconditional? i.e. drop the "else"?
> // Convert pending sequence to external representation, output.
> + // If eof, then just attempt sync.
> if (!traits_type::eq_int_type(__c, traits_type::eof()))
> {
> char_type __pending = traits_type::to_char_type(__c);
> _M_convert_to_external(&__pending, 1, __elen, __plen);
> ! // User code must flush when switching modes (thus don't sync).
> ! if (__elen == __plen)
> ! {
> ! _M_set_indeterminate();
> ! __ret = traits_type::not_eof(__c);
> ! }
> ! }
> ! else if (!_M_file.sync())
> {
> _M_set_indeterminate();
> __ret = traits_type::not_eof(__c);
Why do we need an fflush here at all?
> If the user must now flush to switch modes, this should always be a safe
> optimization.
My patch didn't change that; that will be a later, trunk-only patch. But I
think your change is still safe.
Jason