File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -572,6 +572,7 @@ new_buffersize(fileio *self, size_t currentsize
572572#endif
573573 )
574574{
575+ size_t addend ;
575576#ifdef HAVE_FSTAT
576577 if (end != (Py_off_t )- 1 ) {
577578 /* Files claiming a size smaller than SMALLCHUNK may
@@ -589,9 +590,16 @@ new_buffersize(fileio *self, size_t currentsize
589590 }
590591#endif
591592 /* Expand the buffer by an amount proportional to the current size,
592- giving us amortized linear-time behavior. Use a less-than-double
593- growth factor to avoid excessive allocation. */
594- return currentsize + (currentsize >> 3 ) + 6 ;
593+ giving us amortized linear-time behavior. For bigger sizes, use a
594+ less-than-double growth factor to avoid excessive allocation. */
595+ if (currentsize > 65536 )
596+ addend = currentsize >> 3 ;
597+ else
598+ addend = 256 + currentsize ;
599+ if (addend < SMALLCHUNK )
600+ /* Avoid tiny read() calls. */
601+ addend = SMALLCHUNK ;
602+ return addend + currentsize ;
595603}
596604
597605static PyObject *
You can’t perform that action at this time.
0 commit comments