diff options
author | dgp <dgp@users.sourceforge.net> | 2009-02-10 17:28:37 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2009-02-10 17:28:37 (GMT) |
commit | d1aef8650a1ebf59f57b1c605264aadcc928fa57 (patch) | |
tree | ffcc598db32fc22c08fb48544aca25f029d24705 /generic/tclStringObj.c | |
parent | 53dbabfac015bf2ff02f18a116d9543d1bfb90c9 (diff) | |
download | tcl-d1aef8650a1ebf59f57b1c605264aadcc928fa57.zip tcl-d1aef8650a1ebf59f57b1c605264aadcc928fa57.tar.gz tcl-d1aef8650a1ebf59f57b1c605264aadcc928fa57.tar.bz2 |
Simplify SetStringFromAny() by removing unreachable and duplicate code.
Diffstat (limited to 'generic/tclStringObj.c')
-rw-r--r-- | generic/tclStringObj.c | 38 |
1 files changed, 13 insertions, 25 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index eef8b1d..15ed7af 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -33,7 +33,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclStringObj.c,v 1.91 2009/02/10 17:09:09 dgp Exp $ */ + * RCS: @(#) $Id: tclStringObj.c,v 1.92 2009/02/10 17:28:37 dgp Exp $ */ #include "tclInt.h" #include "tommath.h" @@ -2841,39 +2841,27 @@ SetStringFromAny( Tcl_Interp *interp, /* Used for error reporting if not NULL. */ register Tcl_Obj *objPtr) /* The object to convert. */ { - /* - * The Unicode object is optimized for the case where each UTF char in a - * string is only one byte. In this case, we store the value of numChars, - * but we don't copy the bytes to the unicodeObj->unicode. - */ - if (objPtr->typePtr != &tclStringType) { - String *stringPtr; + String *stringPtr = (String *) ckalloc((unsigned) sizeof(String)); - if (objPtr->typePtr != NULL) { - if (objPtr->bytes == NULL) { - objPtr->typePtr->updateStringProc(objPtr); - } - TclFreeIntRep(objPtr); - } - objPtr->typePtr = &tclStringType; + /* + * Convert whatever we have into an untyped value. Just A String. + */ + + (void) TclGetString(objPtr); + TclFreeIntRep(objPtr); /* - * Allocate enough space for the basic String structure. + * Create a basic String intrep that just points to the UTF-8 string + * already in place at objPtr->bytes. */ - stringPtr = stringAlloc(STRING_UALLOC(0)); stringPtr->numChars = -1; - stringPtr->uallocated = STRING_UALLOC(0); + stringPtr->allocated = objPtr->length; + stringPtr->uallocated = 0; stringPtr->hasUnicode = 0; - - if (objPtr->bytes != NULL) { - stringPtr->allocated = objPtr->length; - objPtr->bytes[objPtr->length] = 0; - } else { - objPtr->length = 0; - } SET_STRING(objPtr, stringPtr); + objPtr->typePtr = &tclStringType; } return TCL_OK; } |