2004-09-22 Jeff Johnston <jjohnstn@redhat.com>

* libc/stdio/fread.c (fread):  For non-space-optimized case,
        add special code for unbuffered files to use user buffer and
        only require one low-level system read.
This commit is contained in:
Jeff Johnston 2004-09-22 21:22:07 +00:00
parent 71de401447
commit 602de58268
2 changed files with 81 additions and 18 deletions

View File

@ -1,3 +1,9 @@
2004-09-22 Jeff Johnston <jjohnstn@redhat.com>
* libc/stdio/fread.c (fread): For non-space-optimized case,
add special code for unbuffered files to use user buffer and
only require one low-level system read.
2004-09-21 Ian Lance Taylor <ian@wasabisystems.com> 2004-09-21 Ian Lance Taylor <ian@wasabisystems.com>
* libc/machine/xscale/setjmp.S: New file, copied from * libc/machine/xscale/setjmp.S: New file, copied from

View File

@ -130,6 +130,60 @@ _DEFUN(fread, (buf, size, count, fp),
total = resid; total = resid;
p = buf; p = buf;
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
/* Optimize unbuffered I/O. */
if (fp->_flags & __SNBF)
{
/* First copy any available characters from ungetc buffer. */
int copy_size = resid > fp->_r ? fp->_r : resid;
_CAST_VOID memcpy ((_PTR) p, (_PTR) fp->_p, (size_t) copy_size);
fp->_p += copy_size;
fp->_r -= copy_size;
p += copy_size;
resid -= copy_size;
/* If still more data needed, free any allocated ungetc buffer. */
if (HASUB (fp) && resid > 0)
FREEUB (fp);
/* Finally read directly into user's buffer if needed. */
if (resid > 0)
{
int rc = 0;
/* save fp buffering state */
void *old_base = fp->_bf._base;
void * old_p = fp->_p;
int old_size = fp->_bf._size;
/* allow __refill to use user's buffer */
fp->_bf._base = p;
fp->_bf._size = resid;
fp->_p = p;
rc = __srefill (fp);
/* restore fp buffering back to original state */
resid -= fp->_r;
fp->_r = 0;
fp->_bf._base = old_base;
fp->_bf._size = old_size;
fp->_p = old_p;
if (rc)
{
/* no more input: return partial result */
#ifdef __SCLE
if (fp->_flags & __SCLE)
{
_funlockfile (fp);
return crlf (fp, buf, total-resid, 1) / size;
}
#endif
_funlockfile (fp);
return (total - resid) / size;
}
}
}
else
#endif /* !PREFER_SIZE_OVER_SPEED && !__OPTIMIZE_SIZE__ */
{
while (resid > (r = fp->_r)) while (resid > (r = fp->_r))
{ {
_CAST_VOID memcpy ((_PTR) p, (_PTR) fp->_p, (size_t) r); _CAST_VOID memcpy ((_PTR) p, (_PTR) fp->_p, (size_t) r);
@ -154,6 +208,9 @@ _DEFUN(fread, (buf, size, count, fp),
_CAST_VOID memcpy ((_PTR) p, (_PTR) fp->_p, resid); _CAST_VOID memcpy ((_PTR) p, (_PTR) fp->_p, resid);
fp->_r -= resid; fp->_r -= resid;
fp->_p += resid; fp->_p += resid;
}
/* Perform any CR/LF clean-up if necessary. */
#ifdef __SCLE #ifdef __SCLE
if (fp->_flags & __SCLE) if (fp->_flags & __SCLE)
{ {