[Python-checkins] cpython: _PyBytesWriter: rename size attribute to min_size

victor.stinner python-checkins at python.org
Fri Oct 9 07:16:34 EDT 2015


https://hg.python.org/cpython/rev/9c8724ec0e00
changeset:   98616:9c8724ec0e00
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Fri Oct 09 12:37:03 2015 +0200
summary:
  _PyBytesWriter: rename size attribute to min_size

files:
  Include/bytesobject.h |   5 +++--
  Objects/bytesobject.c |  14 +++++++-------
  2 files changed, 10 insertions(+), 9 deletions(-)


diff --git a/Include/bytesobject.h b/Include/bytesobject.h
--- a/Include/bytesobject.h
+++ b/Include/bytesobject.h
@@ -134,8 +134,9 @@
     /* Number of allocated size */
     Py_ssize_t allocated;
 
-    /* Current size of the buffer (can be smaller than the allocated size) */
-    Py_ssize_t size;
+    /* Minimum number of allocated bytes,
+       incremented by _PyBytesWriter_Prepare() */
+    Py_ssize_t min_size;
 
     /* If non-zero, overallocate the buffer (default: 0). */
     int overallocate;
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -3821,7 +3821,7 @@
 {
     writer->buffer = NULL;
     writer->allocated = 0;
-    writer->size = 0;
+    writer->min_size = 0;
     writer->overallocate = 0;
     writer->use_small_buffer = 0;
 #ifdef Py_DEBUG
@@ -3874,7 +3874,7 @@
     }
 
     start = _PyBytesWriter_AsString(writer);
-    assert(0 <= writer->size && writer->size <= writer->allocated);
+    assert(0 <= writer->min_size && writer->min_size <= writer->allocated);
     /* the last byte must always be null */
     assert(start[writer->allocated] == 0);
 
@@ -3897,18 +3897,18 @@
         return str;
     }
 
-    if (writer->size > PY_SSIZE_T_MAX - size) {
+    if (writer->min_size > PY_SSIZE_T_MAX - size) {
         PyErr_NoMemory();
         _PyBytesWriter_Dealloc(writer);
         return NULL;
     }
-    writer->size += size;
+    writer->min_size += size;
 
     allocated = writer->allocated;
-    if (writer->size <= allocated)
+    if (writer->min_size <= allocated)
         return str;
 
-    allocated = writer->size;
+    allocated = writer->min_size;
     if (writer->overallocate
         && allocated <= (PY_SSIZE_T_MAX - allocated / OVERALLOCATE_FACTOR)) {
         /* overallocate to limit the number of realloc() */
@@ -3957,7 +3957,7 @@
 _PyBytesWriter_Alloc(_PyBytesWriter *writer, Py_ssize_t size)
 {
     /* ensure that _PyBytesWriter_Alloc() is only called once */
-    assert(writer->size == 0 && writer->buffer == NULL);
+    assert(writer->min_size == 0 && writer->buffer == NULL);
     assert(size >= 0);
 
     writer->use_small_buffer = 1;

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list