diff options
| author | hobbs <hobbs> | 2007-11-07 23:52:20 (GMT) |
|---|---|---|
| committer | hobbs <hobbs> | 2007-11-07 23:52:20 (GMT) |
| commit | 84a07bcad00ca27e7f08b5ea7756eae6c14d461a (patch) | |
| tree | 909dfc366edec26701ba6da699d8b420f75ab768 | |
| parent | 95d31ccc849864f544ec1344c70ed63114e8dbf0 (diff) | |
| download | tcl-84a07bcad00ca27e7f08b5ea7756eae6c14d461a.zip tcl-84a07bcad00ca27e7f08b5ea7756eae6c14d461a.tar.gz tcl-84a07bcad00ca27e7f08b5ea7756eae6c14d461a.tar.bz2 | |
(DoWriteChars): special case for 1-byte channel write.
| -rw-r--r-- | ChangeLog | 1 | ||||
| -rw-r--r-- | generic/tclIO.c | 17 |
2 files changed, 12 insertions, 6 deletions
@@ -2,6 +2,7 @@ * generic/tclIO.c (TclGetsObjBinary): add an efficient binary path for [gets]. + (DoWriteChars): special case for 1-byte channel write. 2007-11-06 Miguel Sofer <msofer@users.sf.net> diff --git a/generic/tclIO.c b/generic/tclIO.c index f157f7e..a7043bb 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclIO.c,v 1.125 2007/11/07 19:18:03 hobbs Exp $ + * RCS: @(#) $Id: tclIO.c,v 1.126 2007/11/07 23:52:21 hobbs Exp $ */ #include "tclInt.h" @@ -3232,15 +3232,20 @@ DoWriteChars( /* * Inefficient way to convert UTF-8 to byte-array, but the code * parallels the way it is done for objects. + * Special case for 1-byte (used by eg [puts] for the \n) could + * be extended to more efficient translation of the src string. */ - Tcl_Obj *objPtr; int result; - objPtr = Tcl_NewStringObj(src, len); - src = (char *) Tcl_GetByteArrayFromObj(objPtr, &len); - result = WriteBytes(chanPtr, src, len); - TclDecrRefCount(objPtr); + if ((len == 1) && (UCHAR(*src) < 0xC0)) { + result = WriteBytes(chanPtr, src, len); + } else { + Tcl_Obj *objPtr = Tcl_NewStringObj(src, len); + src = (char *) Tcl_GetByteArrayFromObj(objPtr, &len); + result = WriteBytes(chanPtr, src, len); + TclDecrRefCount(objPtr); + } return result; } return WriteChars(chanPtr, src, len); |
