diff options
author | Lauri Kasanen <cand@gmx.com> | 2013-03-26 16:20:20 +0200 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2013-03-27 11:04:08 +1000 |
commit | 1973875822fea7889477f0c1423dfa9eabc02459 (patch) | |
tree | fee8dbd21f0bdee7aefe5fd6b1bbdd0c70dc302e | |
parent | d2dc691ed373832aa7b3c93971439a9762543db2 (diff) | |
download | jimtcl-1973875822fea7889477f0c1423dfa9eabc02459.zip jimtcl-1973875822fea7889477f0c1423dfa9eabc02459.tar.gz jimtcl-1973875822fea7889477f0c1423dfa9eabc02459.tar.bz2 |
Remove most quotingType allocations in JimMakeListStringRep
Only two bits are needed, so also change to unsigned char from int.
Signed-off-by: Lauri Kasanen <cand@gmx.com>
-rw-r--r-- | jim.c | 19 |
1 files changed, 14 insertions, 5 deletions
@@ -5947,7 +5947,7 @@ void DupListInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr) #define JIM_ELESTR_SIMPLE 0 #define JIM_ELESTR_BRACE 1 #define JIM_ELESTR_QUOTE 2 -static int ListElementQuotingType(const char *s, int len) +static unsigned char ListElementQuotingType(const char *s, int len) { int i, level, blevel, trySimple = 1; @@ -6100,13 +6100,19 @@ static int BackslashQuoteString(const char *s, char *q) static void JimMakeListStringRep(Jim_Obj *objPtr, Jim_Obj **objv, int objc) { + #define STATIC_QUOTING_LEN 32 int i, bufLen, realLength; const char *strRep; char *p; - int *quotingType; + unsigned char *quotingType, staticQuoting[STATIC_QUOTING_LEN]; - /* (Over) Estimate the space needed. */ - quotingType = Jim_Alloc(sizeof(int) * objc + 1); + /* Estimate the space needed. */ + if (objc > STATIC_QUOTING_LEN) { + quotingType = Jim_Alloc(objc); + } + else { + quotingType = staticQuoting; + } bufLen = 0; for (i = 0; i < objc; i++) { int len; @@ -6172,7 +6178,10 @@ static void JimMakeListStringRep(Jim_Obj *objPtr, Jim_Obj **objv, int objc) } *p = '\0'; /* nul term. */ objPtr->length = realLength; - Jim_Free(quotingType); + + if (quotingType != staticQuoting) { + Jim_Free(quotingType); + } } static void UpdateStringOfList(struct Jim_Obj *objPtr) |