diff options
author | Kevin B Kenny <kennykb@acm.org> | 2015-10-24 02:37:02 (GMT) |
---|---|---|
committer | Kevin B Kenny <kennykb@acm.org> | 2015-10-24 02:37:02 (GMT) |
commit | 4174e5c5cc258660142a1912dd563a05272d50ba (patch) | |
tree | e381e37399e8327e7f6effc755d2a8d586e1bbb9 | |
parent | 8ce8f6e7d85681c0d5fbd53cc64194d6622f12dd (diff) | |
download | tcl-4174e5c5cc258660142a1912dd563a05272d50ba.zip tcl-4174e5c5cc258660142a1912dd563a05272d50ba.tar.gz tcl-4174e5c5cc258660142a1912dd563a05272d50ba.tar.bz2 |
merge changes from pspjuth that optimize conversion from unichar to utf and add optimized versions for reading a word from byte codes.
-rw-r--r-- | generic/tclCompile.h | 31 | ||||
-rw-r--r-- | generic/tclInt.h | 1 | ||||
-rw-r--r-- | generic/tclStringObj.c | 4 | ||||
-rw-r--r-- | generic/tclUtf.c | 17 |
4 files changed, 42 insertions, 11 deletions
diff --git a/generic/tclCompile.h b/generic/tclCompile.h index b89346d..f9fddf3 100644 --- a/generic/tclCompile.h +++ b/generic/tclCompile.h @@ -1516,6 +1516,37 @@ MODULE_SCOPE int TclPushProcCallFrame(ClientData clientData, (*((p)+3))) /* + * Override TclGetUInt4AtPtr or TclGetInt4AtPtr macros if + * a known better version exists. + */ +#ifdef WORDS_BIGENDIAN +#define OVERRIDE_INT4(i) (i) +#elif defined(__GNUC__) && (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)) +#define OVERRIDE_INT4(i) __builtin_bswap32(i) +#elif defined(_MSC_VER) && _MSC_VER>=1300 +#define OVERRIDE_INT4(i) _byteswap_ulong(i) +#endif + +#ifdef OVERRIDE_INT4 +#undef TclGetUInt4AtPtr +static inline unsigned int +TclGetUInt4AtPtr(const unsigned char *p) +{ + uint32_t i; + memcpy(&i,p,4); + return OVERRIDE_INT4(i); +} +#undef TclGetInt4AtPtr +static inline signed int +TclGetInt4AtPtr(const unsigned char *p) +{ + int32_t i; + memcpy(&i,p,4); + return OVERRIDE_INT4(i); +} +#endif /* OVERRIDE_INT4 */ + +/* * Macros used to compute the minimum and maximum of two integers. The ANSI C * "prototypes" for these macros are: * diff --git a/generic/tclInt.h b/generic/tclInt.h index 50eb370..6c39558 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -3133,6 +3133,7 @@ MODULE_SCOPE int TclTrimLeft(const char *bytes, int numBytes, MODULE_SCOPE int TclTrimRight(const char *bytes, int numBytes, const char *trim, int numTrim); MODULE_SCOPE int TclUtfCasecmp(const char *cs, const char *ct); +MODULE_SCOPE int TclUtfCount(Tcl_UniChar ch); MODULE_SCOPE Tcl_Obj * TclpNativeToNormalized(ClientData clientData); MODULE_SCOPE Tcl_Obj * TclpFilesystemPathType(Tcl_Obj *pathPtr); MODULE_SCOPE int TclpDlopen(Tcl_Interp *interp, Tcl_Obj *pathPtr, diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index 8d70d20..1974079 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -3097,7 +3097,7 @@ ExtendStringRepWithUnicode( */ int i, origLength, size = 0; - char *dst, buf[TCL_UTF_MAX]; + char *dst; String *stringPtr = GET_STRING(objPtr); if (numChars < 0) { @@ -3123,7 +3123,7 @@ ExtendStringRepWithUnicode( } for (i = 0; i < numChars && size >= 0; i++) { - size += Tcl_UniCharToUtf((int) unicode[i], buf); + size += TclUtfCount(unicode[i]); } if (size < 0) { Tcl_Panic("max size for a Tcl value (%d bytes) exceeded", INT_MAX); diff --git a/generic/tclUtf.c b/generic/tclUtf.c index b878149..f585c03 100644 --- a/generic/tclUtf.c +++ b/generic/tclUtf.c @@ -89,12 +89,11 @@ static const unsigned char totalBytes[256] = { * Functions used only in this module. */ -static int UtfCount(int ch); /* *--------------------------------------------------------------------------- * - * UtfCount -- + * TclUtfCount -- * * Find the number of bytes in the Utf character "ch". * @@ -107,9 +106,9 @@ static int UtfCount(int ch); *--------------------------------------------------------------------------- */ -INLINE static int -UtfCount( - int ch) /* The Tcl_UniChar whose size is returned. */ +INLINE int +TclUtfCount( + Tcl_UniChar ch) /* The Tcl_UniChar whose size is returned. */ { if ((ch > 0) && (ch < UNICODE_SELF)) { return 1; @@ -829,7 +828,7 @@ Tcl_UtfToUpper( * char to dst if its size is <= the original char. */ - if (bytes < UtfCount(upChar)) { + if (bytes < TclUtfCount(upChar)) { memcpy(dst, src, (size_t) bytes); dst += bytes; } else { @@ -882,7 +881,7 @@ Tcl_UtfToLower( * char to dst if its size is <= the original char. */ - if (bytes < UtfCount(lowChar)) { + if (bytes < TclUtfCount(lowChar)) { memcpy(dst, src, (size_t) bytes); dst += bytes; } else { @@ -932,7 +931,7 @@ Tcl_UtfToTitle( bytes = TclUtfToUniChar(src, &ch); titleChar = Tcl_UniCharToTitle(ch); - if (bytes < UtfCount(titleChar)) { + if (bytes < TclUtfCount(titleChar)) { memcpy(dst, src, (size_t) bytes); dst += bytes; } else { @@ -944,7 +943,7 @@ Tcl_UtfToTitle( bytes = TclUtfToUniChar(src, &ch); lowChar = Tcl_UniCharToLower(ch); - if (bytes < UtfCount(lowChar)) { + if (bytes < TclUtfCount(lowChar)) { memcpy(dst, src, (size_t) bytes); dst += bytes; } else { |