mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Speed up reading of small files. This avoids multiple C read() calls on pyc files.
This commit is contained in:
parent
006917ec7f
commit
a3f4457b17
1 changed files with 11 additions and 3 deletions
|
@ -572,6 +572,7 @@ new_buffersize(fileio *self, size_t currentsize
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
size_t addend;
|
||||||
#ifdef HAVE_FSTAT
|
#ifdef HAVE_FSTAT
|
||||||
if (end != (Py_off_t)-1) {
|
if (end != (Py_off_t)-1) {
|
||||||
/* Files claiming a size smaller than SMALLCHUNK may
|
/* Files claiming a size smaller than SMALLCHUNK may
|
||||||
|
@ -589,9 +590,16 @@ new_buffersize(fileio *self, size_t currentsize
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* Expand the buffer by an amount proportional to the current size,
|
/* Expand the buffer by an amount proportional to the current size,
|
||||||
giving us amortized linear-time behavior. Use a less-than-double
|
giving us amortized linear-time behavior. For bigger sizes, use a
|
||||||
growth factor to avoid excessive allocation. */
|
less-than-double growth factor to avoid excessive allocation. */
|
||||||
return currentsize + (currentsize >> 3) + 6;
|
if (currentsize > 65536)
|
||||||
|
addend = currentsize >> 3;
|
||||||
|
else
|
||||||
|
addend = 256 + currentsize;
|
||||||
|
if (addend < SMALLCHUNK)
|
||||||
|
/* Avoid tiny read() calls. */
|
||||||
|
addend = SMALLCHUNK;
|
||||||
|
return addend + currentsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue