diff options
author | pooryorick <com.digitalsmarties@pooryorick.com> | 2023-04-12 18:37:24 (GMT) |
---|---|---|
committer | pooryorick <com.digitalsmarties@pooryorick.com> | 2023-04-12 18:37:24 (GMT) |
commit | 786549398b6153ecd72b8c4df20d1bb13457a48d (patch) | |
tree | 9168c8dbe39ac87144dbc88f8221e5c0265af874 /generic/tclIO.c | |
parent | ae5de56339d42d00ed4e2f831148881ab29286dc (diff) | |
download | tcl-786549398b6153ecd72b8c4df20d1bb13457a48d.zip tcl-786549398b6153ecd72b8c4df20d1bb13457a48d.tar.gz tcl-786549398b6153ecd72b8c4df20d1bb13457a48d.tar.bz2 |
Rearrange code blocks in DoReadChars to do less work when returning early.
Diffstat (limited to 'generic/tclIO.c')
-rw-r--r-- | generic/tclIO.c | 57 |
1 files changed, 31 insertions, 26 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c index c0a42be..db0fa0d 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -5936,32 +5936,6 @@ DoReadChars( #define UTF_EXPANSION_FACTOR 1024 int factor = UTF_EXPANSION_FACTOR; - binaryMode = (encoding == GetBinaryEncoding()) - && (statePtr->inputTranslation == TCL_TRANSLATE_LF) - && (statePtr->inEofChar == '\0'); - - if (appendFlag) { - if (binaryMode && (NULL == Tcl_GetByteArrayFromObj(objPtr, (size_t *)NULL))) { - binaryMode = 0; - } - } else { - if (binaryMode) { - Tcl_SetByteArrayLength(objPtr, 0); - } else { - Tcl_SetObjLength(objPtr, 0); - - /* - * We're going to access objPtr->bytes directly, so we must ensure - * that this is actually a string object (otherwise it might have - * been pure Unicode). - * - * Probably not needed anymore. - */ - - TclGetString(objPtr); - } - } - if (GotFlag(statePtr, CHANNEL_ENCODING_ERROR)) { /* TODO: We don't need this call? */ UpdateInterest(chanPtr); @@ -6006,6 +5980,37 @@ DoReadChars( chanPtr = statePtr->topChanPtr; TclChannelPreserve((Tcl_Channel)chanPtr); + + binaryMode = (encoding == GetBinaryEncoding()) + && (statePtr->inputTranslation == TCL_TRANSLATE_LF) + && (statePtr->inEofChar == '\0'); + + if (appendFlag) { + if (binaryMode && (NULL == Tcl_GetByteArrayFromObj(objPtr, (size_t *)NULL))) { + binaryMode = 0; + } + } else { + if (binaryMode) { + Tcl_SetByteArrayLength(objPtr, 0); + } else { + Tcl_SetObjLength(objPtr, 0); + + /* + * We're going to access objPtr->bytes directly, so we must ensure + * that this is actually a string object (otherwise it might have + * been pure Unicode). + * + * Probably not needed anymore. + */ + + TclGetString(objPtr); + } + } + + + + + /* * Must clear the BLOCKED|EOF flags here since we check before reading. */ |