newlib: fix fseek optimization with SEEK_CUR
The call to fflush was invalidating the read buffer, preventing relative seeks to positions that would have been inside the read buffer from being optimized. The call to srefill would then re-read mostly the same data that was initially in the read buffer.
This commit is contained in:
parent
1626569222
commit
59362c80e3
|
@ -141,31 +141,12 @@ _fseeko_r (struct _reent *ptr,
|
||||||
switch (whence)
|
switch (whence)
|
||||||
{
|
{
|
||||||
case SEEK_CUR:
|
case SEEK_CUR:
|
||||||
/*
|
curoff = _ftello_r(ptr, fp);
|
||||||
* In order to seek relative to the current stream offset,
|
|
||||||
* we have to first find the current stream offset a la
|
|
||||||
* ftell (see ftell for details).
|
|
||||||
*/
|
|
||||||
_fflush_r (ptr, fp); /* may adjust seek offset on append stream */
|
|
||||||
if (fp->_flags & __SOFF)
|
|
||||||
curoff = fp->_offset;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
curoff = seekfn (ptr, fp->_cookie, (_fpos_t) 0, SEEK_CUR);
|
|
||||||
if (curoff == -1L)
|
if (curoff == -1L)
|
||||||
{
|
{
|
||||||
_newlib_flockfile_exit (fp);
|
_newlib_flockfile_exit (fp);
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (fp->_flags & __SRD)
|
|
||||||
{
|
|
||||||
curoff -= fp->_r;
|
|
||||||
if (HASUB (fp))
|
|
||||||
curoff -= fp->_ur;
|
|
||||||
}
|
|
||||||
else if (fp->_flags & __SWR && fp->_p != NULL)
|
|
||||||
curoff += fp->_p - fp->_bf._base;
|
|
||||||
|
|
||||||
offset += curoff;
|
offset += curoff;
|
||||||
whence = SEEK_SET;
|
whence = SEEK_SET;
|
||||||
|
|
|
@ -142,31 +142,12 @@ _fseeko64_r (struct _reent *ptr,
|
||||||
switch (whence)
|
switch (whence)
|
||||||
{
|
{
|
||||||
case SEEK_CUR:
|
case SEEK_CUR:
|
||||||
/*
|
curoff = _ftello64_r(ptr, fp);
|
||||||
* In order to seek relative to the current stream offset,
|
|
||||||
* we have to first find the current stream offset a la
|
|
||||||
* ftell (see ftell for details).
|
|
||||||
*/
|
|
||||||
_fflush_r (ptr, fp); /* may adjust seek offset on append stream */
|
|
||||||
if (fp->_flags & __SOFF)
|
|
||||||
curoff = fp->_offset;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
curoff = seekfn (ptr, fp->_cookie, (_fpos64_t) 0, SEEK_CUR);
|
|
||||||
if (curoff == -1L)
|
if (curoff == -1L)
|
||||||
{
|
{
|
||||||
_newlib_flockfile_exit (fp);
|
_newlib_flockfile_exit (fp);
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (fp->_flags & __SRD)
|
|
||||||
{
|
|
||||||
curoff -= fp->_r;
|
|
||||||
if (HASUB (fp))
|
|
||||||
curoff -= fp->_ur;
|
|
||||||
}
|
|
||||||
else if (fp->_flags & __SWR && fp->_p != NULL)
|
|
||||||
curoff += fp->_p - fp->_bf._base;
|
|
||||||
|
|
||||||
offset += curoff;
|
offset += curoff;
|
||||||
whence = SEEK_SET;
|
whence = SEEK_SET;
|
||||||
|
|
Loading…
Reference in New Issue