Subject: The Tcl*(Scan|Convert)*Element() routines only need chars, not ints, to hold their flags. Reduce waste now that interface freedom permits it.

From: dgp <[email-masked]>
Date: Tue, 8 Jan 2013 17:10:04 +0000

---
 generic/tcl.decls     |  8 ++++----
 generic/tclDecls.h    | 16 ++++++++--------
 generic/tclDictObj.c  |  4 ++--
 generic/tclIndexObj.c |  3 ++-
 generic/tclInt.h      |  4 ++--
 generic/tclListObj.c  |  4 ++--
 generic/tclUtil.c     | 32 ++++++++++++++++----------------
 7 files changed, 36 insertions(+), 35 deletions(-)

diff --git a/generic/tcl.decls b/generic/tcl.decls
index fe1d763..1084144 100644
--- a/generic/tcl.decls
+++ b/generic/tcl.decls
@@ -310,11 +310,11 @@ declare 83 {
     char *Tcl_Concat(int argc, const char *const *argv)
 }
 declare 84 {
-    int Tcl_ConvertElement(const char *src, char *dst, int flags)
+    int Tcl_ConvertElement(const char *src, char *dst, char flags)
 }
 declare 85 {
     int Tcl_ConvertCountedElement(const char *src, int length, char *dst,
-	    int flags)
+	    char flags)
 }
 declare 86 {
     int Tcl_CreateAlias(Tcl_Interp *slave, const char *slaveCmd,
@@ -778,10 +778,10 @@ declare 217 {
     void Tcl_ResetResult(Tcl_Interp *interp)
 }
 declare 218 {
-    int Tcl_ScanElement(const char *src, int *flagPtr)
+    int Tcl_ScanElement(const char *src, char *flagPtr)
 }
 declare 219 {
-    int Tcl_ScanCountedElement(const char *src, int length, int *flagPtr)
+    int Tcl_ScanCountedElement(const char *src, int length, char *flagPtr)
 }
 # Removed in Tcl 9
 #declare 220 {
diff --git a/generic/tclDecls.h b/generic/tclDecls.h
index 0770e98..e6c63b3 100644
--- a/generic/tclDecls.h
+++ b/generic/tclDecls.h
@@ -257,10 +257,10 @@ TCLAPI int		Tcl_CommandComplete(const char *cmd);
 TCLAPI char *		Tcl_Concat(int argc, const char *const *argv);
 /* 84 */
 TCLAPI int		Tcl_ConvertElement(const char *src, char *dst,
-				int flags);
+				char flags);
 /* 85 */
 TCLAPI int		Tcl_ConvertCountedElement(const char *src,
-				int length, char *dst, int flags);
+				int length, char *dst, char flags);
 /* 86 */
 TCLAPI int		Tcl_CreateAlias(Tcl_Interp *slave,
 				const char *slaveCmd, Tcl_Interp *target,
@@ -625,10 +625,10 @@ TCLAPI void		Tcl_Release(ClientData clientData);
 /* 217 */
 TCLAPI void		Tcl_ResetResult(Tcl_Interp *interp);
 /* 218 */
-TCLAPI int		Tcl_ScanElement(const char *src, int *flagPtr);
+TCLAPI int		Tcl_ScanElement(const char *src, char *flagPtr);
 /* 219 */
 TCLAPI int		Tcl_ScanCountedElement(const char *src, int length,
-				int *flagPtr);
+				char *flagPtr);
 /* Slot 220 is reserved */
 /* 221 */
 TCLAPI int		Tcl_ServiceAll(void);
@@ -1877,8 +1877,8 @@ typedef struct TclStubs {
     int (*tcl_Close) (Tcl_Interp *interp, Tcl_Channel chan); /* 81 */
     int (*tcl_CommandComplete) (const char *cmd); /* 82 */
     char * (*tcl_Concat) (int argc, const char *const *argv); /* 83 */
-    int (*tcl_ConvertElement) (const char *src, char *dst, int flags); /* 84 */
-    int (*tcl_ConvertCountedElement) (const char *src, int length, char *dst, int flags); /* 85 */
+    int (*tcl_ConvertElement) (const char *src, char *dst, char flags); /* 84 */
+    int (*tcl_ConvertCountedElement) (const char *src, int length, char *dst, char flags); /* 85 */
     int (*tcl_CreateAlias) (Tcl_Interp *slave, const char *slaveCmd, Tcl_Interp *target, const char *targetCmd, int argc, const char *const *argv); /* 86 */
     int (*tcl_CreateAliasObj) (Tcl_Interp *slave, const char *slaveCmd, Tcl_Interp *target, const char *targetCmd, int objc, Tcl_Obj *const objv[]); /* 87 */
     Tcl_Channel (*tcl_CreateChannel) (const Tcl_ChannelType *typePtr, const char *chanName, ClientData instanceData, int mask); /* 88 */
@@ -2019,8 +2019,8 @@ typedef struct TclStubs {
     void (*tcl_RegExpRange) (Tcl_RegExp regexp, int index, const char **startPtr, const char **endPtr); /* 215 */
     void (*tcl_Release) (ClientData clientData); /* 216 */
     void (*tcl_ResetResult) (Tcl_Interp *interp); /* 217 */
-    int (*tcl_ScanElement) (const char *src, int *flagPtr); /* 218 */
-    int (*tcl_ScanCountedElement) (const char *src, int length, int *flagPtr); /* 219 */
+    int (*tcl_ScanElement) (const char *src, char *flagPtr); /* 218 */
+    int (*tcl_ScanCountedElement) (const char *src, int length, char *flagPtr); /* 219 */
     void (*reserved220)(void);
     int (*tcl_ServiceAll) (void); /* 221 */
     int (*tcl_ServiceEvent) (int flags); /* 222 */
diff --git a/generic/tclDictObj.c b/generic/tclDictObj.c
index 170e744..25124a1 100644
--- a/generic/tclDictObj.c
+++ b/generic/tclDictObj.c
@@ -488,7 +488,7 @@ UpdateStringOfDict(
     Tcl_Obj *dictPtr)
 {
 #define LOCAL_SIZE 20
-    int localFlags[LOCAL_SIZE], *flagPtr = NULL;
+    char localFlags[LOCAL_SIZE], *flagPtr = NULL;
     Dict *dict = dictPtr->internalRep.otherValuePtr;
     ChainEntry *cPtr;
     Tcl_Obj *keyPtr, *valuePtr;
@@ -520,7 +520,7 @@ UpdateStringOfDict(
     } else if (numElems > maxFlags) {
 	Tcl_Panic("max size for a Tcl value (%d bytes) exceeded", INT_MAX);
     } else {
-	flagPtr = ckalloc(numElems * sizeof(int));
+	flagPtr = ckalloc(numElems * sizeof(char));
     }
     for (i=0,cPtr=dict->entryChainHead; i<numElems; i+=2,cPtr=cPtr->nextPtr) {
 	/*
diff --git a/generic/tclIndexObj.c b/generic/tclIndexObj.c
index 512f5ba..7b85481 100644
--- a/generic/tclIndexObj.c
+++ b/generic/tclIndexObj.c
@@ -873,7 +873,8 @@ Tcl_WrongNumArgs(
 				 * NULL. */
 {
     Tcl_Obj *objPtr;
-    int i, len, elemLen, flags;
+    int i, len, elemLen;
+    char flags;
     Interp *iPtr = (Interp *) interp;
     const char *elementStr;
 
diff --git a/generic/tclInt.h b/generic/tclInt.h
index f8d9b08..eb16dd5 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -2880,7 +2880,7 @@ MODULE_SCOPE ContLineLoc *TclContinuationsGet(Tcl_Obj *objPtr);
 MODULE_SCOPE void	TclContinuationsCopy(Tcl_Obj *objPtr,
 			    Tcl_Obj *originObjPtr);
 MODULE_SCOPE int	TclConvertElement(const char *src, int length,
-			    char *dst, int flags);
+			    char *dst, char flags);
 MODULE_SCOPE void	TclDeleteNamespaceVars(Namespace *nsPtr);
 /* TIP #280 - Modified token based evulation, with line information. */
 MODULE_SCOPE int	TclEvalEx(Tcl_Interp *interp, const char *script,
@@ -3085,7 +3085,7 @@ MODULE_SCOPE void	TclRemoveScriptLimitCallbacks(Tcl_Interp *interp);
 MODULE_SCOPE int	TclReToGlob(Tcl_Interp *interp, const char *reStr,
 			    int reStrLen, Tcl_DString *dsPtr, int *flagsPtr);
 MODULE_SCOPE int	TclScanElement(const char *string, int length,
-			    int *flagPtr);
+			    char *flagPtr);
 MODULE_SCOPE void	TclSetBgErrorHandler(Tcl_Interp *interp,
 			    Tcl_Obj *cmdPrefix);
 MODULE_SCOPE void	TclSetBignumIntRep(Tcl_Obj *objPtr,
diff --git a/generic/tclListObj.c b/generic/tclListObj.c
index 85737d5..63db812 100644
--- a/generic/tclListObj.c
+++ b/generic/tclListObj.c
@@ -1924,7 +1924,7 @@ UpdateStringOfList(
     Tcl_Obj *listPtr)		/* List object with string rep to update. */
 {
 #   define LOCAL_SIZE 20
-    int localFlags[LOCAL_SIZE], *flagPtr = NULL;
+    char localFlags[LOCAL_SIZE], *flagPtr = NULL;
     List *listRepPtr = ListRepPtr(listPtr);
     int numElems = listRepPtr->elemCount;
     int i, length, bytesNeeded = 0;
@@ -1961,7 +1961,7 @@ UpdateStringOfList(
 	 * We know numElems <= LIST_MAX, so this is safe.
 	 */
 
-	flagPtr = ckalloc(numElems * sizeof(int));
+	flagPtr = ckalloc(numElems * sizeof(char));
     }
     elemPtrs = &listRepPtr->elements;
     for (i = 0; i < numElems; i++) {
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index df257e8..c8cb75c 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -871,9 +871,9 @@ Tcl_SplitList(
 
 int
 Tcl_ScanElement(
-    register const char *src,	/* String to convert to list element. */
-    register int *flagPtr)	/* Where to store information to guide
-				 * Tcl_ConvertCountedElement. */
+    const char *src,	/* String to convert to list element. */
+    char *flagPtr)	/* Where to store information to guide
+			 * Tcl_ConvertCountedElement. */
 {
     return Tcl_ScanCountedElement(src, -1, flagPtr);
 }
@@ -905,10 +905,10 @@ int
 Tcl_ScanCountedElement(
     const char *src,		/* String to convert to Tcl list element. */
     int length,			/* Number of bytes in src, or -1. */
-    int *flagPtr)		/* Where to store information to guide
+    char *flagPtr)		/* Where to store information to guide
 				 * Tcl_ConvertElement. */
 {
-    int flags = CONVERT_ANY;
+    char flags = CONVERT_ANY;
     int numBytes = TclScanElement(src, length, &flags);
 
     *flagPtr = flags;
@@ -949,7 +949,7 @@ int
 TclScanElement(
     const char *src,		/* String to convert to Tcl list element. */
     int length,			/* Number of bytes in src, or -1. */
-    int *flagPtr)		/* Where to store information to guide
+    char *flagPtr)		/* Where to store information to guide
 				 * Tcl_ConvertElement. */
 {
     const char *p = src;
@@ -1234,9 +1234,9 @@ TclScanElement(
 
 int
 Tcl_ConvertElement(
-    register const char *src,	/* Source information for list element. */
-    register char *dst,		/* Place to put list-ified element. */
-    register int flags)		/* Flags produced by Tcl_ScanElement. */
+    const char *src,	/* Source information for list element. */
+    char *dst,		/* Place to put list-ified element. */
+    char flags)		/* Flags produced by Tcl_ScanElement. */
 {
     return Tcl_ConvertCountedElement(src, -1, dst, flags);
 }
@@ -1267,7 +1267,7 @@ Tcl_ConvertCountedElement(
     register const char *src,	/* Source information for list element. */
     int length,			/* Number of bytes in src, or -1. */
     char *dst,			/* Place to put list-ified element. */
-    int flags)			/* Flags produced by Tcl_ScanElement. */
+    char flags)			/* Flags produced by Tcl_ScanElement. */
 {
     int numBytes = TclConvertElement(src, length, dst, flags);
     dst[numBytes] = '\0';
@@ -1300,9 +1300,9 @@ TclConvertElement(
     register const char *src,	/* Source information for list element. */
     int length,			/* Number of bytes in src, or -1. */
     char *dst,			/* Place to put list-ified element. */
-    int flags)			/* Flags produced by Tcl_ScanElement. */
+    char flags)			/* Flags produced by Tcl_ScanElement. */
 {
-    int conversion = flags & CONVERT_MASK;
+    char conversion = flags & CONVERT_MASK;
     char *p = dst;
 
     /*
@@ -1482,9 +1482,9 @@ Tcl_Merge(
     const char *const *argv)	/* Array of string values. */
 {
 #define LOCAL_SIZE 20
-    int localFlags[LOCAL_SIZE], *flagPtr = NULL;
+    char localFlags[LOCAL_SIZE];
     int i, bytesNeeded = 0;
-    char *result, *dst;
+    char *result, *dst, *flagPtr = NULL;
     const int maxFlags = UINT_MAX / sizeof(int);
 
     /*
@@ -1519,7 +1519,7 @@ Tcl_Merge(
 
 	Tcl_Panic("max size for a Tcl value (%d bytes) exceeded", INT_MAX);
     } else {
-	flagPtr = ckalloc(argc * sizeof(int));
+	flagPtr = ckalloc(argc * sizeof(char));
     }
     for (i = 0; i < argc; i++) {
 	flagPtr[i] = ( i ? TCL_DONT_QUOTE_HASH : 0 );
@@ -2597,7 +2597,7 @@ Tcl_DStringAppendElement(
 {
     char *dst = dsPtr->string + dsPtr->length;
     int needSpace = TclNeedSpace(dsPtr->string, dst);
-    int flags = needSpace ? TCL_DONT_QUOTE_HASH : 0;
+    char flags = needSpace ? TCL_DONT_QUOTE_HASH : 0;
     int newSize = dsPtr->length + needSpace
 	    + TclScanElement(element, -1, &flags);
 
-- 
cgit v0.12