diff options
| author | apnadkarni <apnmbx-wits@yahoo.com> | 2023-05-19 16:47:58 (GMT) |
|---|---|---|
| committer | apnadkarni <apnmbx-wits@yahoo.com> | 2023-05-19 16:47:58 (GMT) |
| commit | 16a75f3cbf8ba7ab30d4f5f1adcd658269d9ae8c (patch) | |
| tree | 05034cc48612753645a36939be59d920c22055b8 /generic/tclBinary.c | |
| parent | 6fa73194d556765f6a8dfe33c0f609377d5fb41c (diff) | |
| download | tcl-16a75f3cbf8ba7ab30d4f5f1adcd658269d9ae8c.zip tcl-16a75f3cbf8ba7ab30d4f5f1adcd658269d9ae8c.tar.gz tcl-16a75f3cbf8ba7ab30d4f5f1adcd658269d9ae8c.tar.bz2 | |
More refactoring into common code
Diffstat (limited to 'generic/tclBinary.c')
| -rw-r--r-- | generic/tclBinary.c | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/generic/tclBinary.c b/generic/tclBinary.c index 4215913..81ea3f3 100644 --- a/generic/tclBinary.c +++ b/generic/tclBinary.c @@ -767,27 +767,14 @@ TclAppendBytesToByteArray( } needed = byteArrayPtr->used + len; if (needed > byteArrayPtr->allocated) { - ByteArray *ptr = NULL; - Tcl_Size attempt; - - /* First try to overallocate, reducing overallocation on each fail */ - attempt = - TclUpsizeAlloc(byteArrayPtr->allocated, needed, BYTEARRAY_MAX_LEN); - while (attempt > needed) { - ptr = (ByteArray *)Tcl_AttemptRealloc(byteArrayPtr, - BYTEARRAY_SIZE(attempt)); - if (ptr) - break; - attempt = TclUpsizeRetry(needed, attempt); - } - - if (ptr == NULL) { - /* Last chance: Try to allocate exactly what is needed. */ - attempt = needed; - ptr = (ByteArray *)Tcl_Realloc(byteArrayPtr, BYTEARRAY_SIZE(attempt)); - } - byteArrayPtr = ptr; - byteArrayPtr->allocated = attempt; + Tcl_Size newCapacity; + byteArrayPtr = + (ByteArray *)TclReallocElemsEx(byteArrayPtr, + needed, + 1, + offsetof(ByteArray, bytes), + &newCapacity); + byteArrayPtr->allocated = newCapacity; SET_BYTEARRAY(irPtr, byteArrayPtr); } |
