diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-04-17 11:50:58 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-04-17 11:50:58 (GMT) |
commit | a3f4457b172a165fafa65d67e0293f89dbba06b7 (patch) | |
tree | f57e82bf1b366f555dab49e51d5ee80b08264786 /Modules/_io/fileio.c | |
parent | 006917ec7fde087d7fe0e06858c8bce45314e5b8 (diff) | |
download | cpython-a3f4457b172a165fafa65d67e0293f89dbba06b7.zip cpython-a3f4457b172a165fafa65d67e0293f89dbba06b7.tar.gz cpython-a3f4457b172a165fafa65d67e0293f89dbba06b7.tar.bz2 |
Speed up reading of small files. This avoids multiple C read() calls on pyc files.
Diffstat (limited to 'Modules/_io/fileio.c')
-rw-r--r-- | Modules/_io/fileio.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index 34ff1e0..df3affe 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -572,6 +572,7 @@ new_buffersize(fileio *self, size_t currentsize #endif ) { + size_t addend; #ifdef HAVE_FSTAT if (end != (Py_off_t)-1) { /* Files claiming a size smaller than SMALLCHUNK may @@ -589,9 +590,16 @@ new_buffersize(fileio *self, size_t currentsize } #endif /* Expand the buffer by an amount proportional to the current size, - giving us amortized linear-time behavior. Use a less-than-double - growth factor to avoid excessive allocation. */ - return currentsize + (currentsize >> 3) + 6; + giving us amortized linear-time behavior. For bigger sizes, use a + less-than-double growth factor to avoid excessive allocation. */ + if (currentsize > 65536) + addend = currentsize >> 3; + else + addend = 256 + currentsize; + if (addend < SMALLCHUNK) + /* Avoid tiny read() calls. */ + addend = SMALLCHUNK; + return addend + currentsize; } static PyObject * |