summaryrefslogtreecommitdiffstats
path: root/generic/tclIO.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2014-03-20 20:18:20 (GMT)
committerdgp <dgp@users.sourceforge.net>2014-03-20 20:18:20 (GMT)
commit60a84571795909d2b51dff06349107716ae3ab6d (patch)
tree991b83a6fd32407ea31ac62ee4b71dab11f31b23 /generic/tclIO.c
parent8c3da02c3e41f1b7e029ed7633e250646fe7ec82 (diff)
downloadtcl-60a84571795909d2b51dff06349107716ae3ab6d.zip
tcl-60a84571795909d2b51dff06349107716ae3ab6d.tar.gz
tcl-60a84571795909d2b51dff06349107716ae3ab6d.tar.bz2
Don't allow buffer recycling to prevent or delay buffersize shrinkage.
Diffstat (limited to 'generic/tclIO.c')
-rw-r--r--generic/tclIO.c68
1 files changed, 28 insertions, 40 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 1a56811..e7653f6 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -2255,13 +2255,12 @@ RecycleBuffer(
}
/*
- * TODO
- * Only save buffers which are at least as big as the requested buffersize
- * for the channel. This is to honor dynamic changes of the buffersize
+ * Only save buffers which have the requested buffersize for the
+ * channel. This is to honor dynamic changes of the buffersize
* made by the user.
*/
- if ((bufPtr->bufLength - BUFFER_PADDING) < statePtr->bufSize) {
+ if ((bufPtr->bufLength - BUFFER_PADDING) != statePtr->bufSize) {
ckfree((char *) bufPtr);
return;
}
@@ -5952,14 +5951,13 @@ GetInput(
statePtr->saveInBufPtr = NULL;
/*
- * TODO
* Check the actual buffersize against the requested buffersize.
- * Buffers which are smaller than requested are squashed. This is done
+ * Saved buffers of the wrong size are squashed. This is done
* to honor dynamic changes of the buffersize made by the user.
*/
if ((bufPtr != NULL)
- && (bufPtr->bufLength - BUFFER_PADDING < statePtr->bufSize)) {
+ && (bufPtr->bufLength - BUFFER_PADDING != statePtr->bufSize)) {
ckfree((char *) bufPtr);
bufPtr = NULL;
}
@@ -5969,22 +5967,8 @@ GetInput(
}
bufPtr->nextPtr = NULL;
- /*
- * TODO
- * SF #427196: Use the actual size of the buffer to determine the
- * number of bytes to read from the channel and not the size for new
- * buffers. They can be different if the buffersize was changed
- * between reads.
- *
- * Note: This affects performance negatively if the buffersize was
- * extended but this small buffer is reused for all subsequent reads.
- * The system never uses buffers with the requested bigger size in
- * that case. An adjunct patch could try and delete all unused buffers
- * it encounters and which are smaller than the formally requested
- * buffersize.
- */
-
toRead = SpaceLeft(bufPtr);
+ assert(toRead == statePtr->bufSize);
if (statePtr->inQueueTail == NULL) {
statePtr->inQueueHead = bufPtr;
@@ -6727,7 +6711,6 @@ Tcl_SetChannelBufferSize(
ChannelState *statePtr; /* State of real channel structure. */
/*
- * TODO
* Clip the buffer size to force it into the [1,1M] range
*/
@@ -6738,7 +6721,27 @@ Tcl_SetChannelBufferSize(
}
statePtr = ((Channel *) chan)->state;
+
+ if (statePtr->bufSize == sz) {
+ return;
+ }
statePtr->bufSize = sz;
+
+ /*
+ * If bufsize changes, need to get rid of old utility buffer.
+ */
+
+ if (statePtr->saveInBufPtr != NULL) {
+ RecycleBuffer(statePtr, statePtr->saveInBufPtr, 1);
+ statePtr->saveInBufPtr = NULL;
+ }
+ if ((statePtr->inQueueHead != NULL)
+ && (statePtr->inQueueHead->nextPtr == NULL)
+ && IsBufferEmpty(statePtr->inQueueHead)) {
+ RecycleBuffer(statePtr, statePtr->inQueueHead, 1);
+ statePtr->inQueueHead = NULL;
+ statePtr->inQueueTail = NULL;
+ }
}
/*
@@ -7172,6 +7175,7 @@ Tcl_SetChannelOption(
return TCL_ERROR;
}
Tcl_SetChannelBufferSize(chan, newBufferSize);
+ return TCL_OK;
} else if (HaveOpt(2, "-encoding")) {
Tcl_Encoding encoding;
@@ -7202,6 +7206,7 @@ Tcl_SetChannelOption(
statePtr->outputEncodingFlags = TCL_ENCODING_START;
ResetFlag(statePtr, CHANNEL_NEED_MORE_DATA);
UpdateInterest(chanPtr);
+ return TCL_OK;
} else if (HaveOpt(2, "-eofchar")) {
if (Tcl_SplitList(interp, newValue, &argc, &argv) == TCL_ERROR) {
return TCL_ERROR;
@@ -7363,23 +7368,6 @@ Tcl_SetChannelOption(
return Tcl_BadChannelOption(interp, optionName, NULL);
}
- /*
- * TODO
- * If bufsize changes, need to get rid of old utility buffer.
- */
-
- if (statePtr->saveInBufPtr != NULL) {
- RecycleBuffer(statePtr, statePtr->saveInBufPtr, 1);
- statePtr->saveInBufPtr = NULL;
- }
- if ((statePtr->inQueueHead != NULL)
- && (statePtr->inQueueHead->nextPtr == NULL)
- && IsBufferEmpty(statePtr->inQueueHead)) {
- RecycleBuffer(statePtr, statePtr->inQueueHead, 1);
- statePtr->inQueueHead = NULL;
- statePtr->inQueueTail = NULL;
- }
-
return TCL_OK;
}