diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2002-05-29 10:35:34 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2002-05-29 10:35:34 (GMT) |
commit | 52319201a0f33f5984298267ba05ede5689eb818 (patch) | |
tree | 69690c28d7ea044538f1557ec58740707718d328 /generic | |
parent | 3a1941e7d007e93449aa22085687a8fafaddad7e (diff) | |
download | tcl-52319201a0f33f5984298267ba05ede5689eb818.zip tcl-52319201a0f33f5984298267ba05ede5689eb818.tar.gz tcl-52319201a0f33f5984298267ba05ede5689eb818.tar.bz2 |
Made Tcl_UniCharNcmp faster on big-endian machines; the system memcmp()is
probably optimized far in excess of anything we could do! Little-endian
just use the old code...
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclCmdMZ.c | 4 | ||||
-rw-r--r-- | generic/tclExecute.c | 4 | ||||
-rw-r--r-- | generic/tclInt.h | 19 | ||||
-rw-r--r-- | generic/tclUtf.c | 15 |
4 files changed, 33 insertions, 9 deletions
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index a3b03df..3707ca4 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -14,7 +14,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclCmdMZ.c,v 1.68 2002/05/29 09:09:57 hobbs Exp $ + * RCS: @(#) $Id: tclCmdMZ.c,v 1.69 2002/05/29 10:35:45 dkf Exp $ */ #include "tclInt.h" @@ -1329,7 +1329,7 @@ Tcl_StringObjCmd(dummy, interp, objc, objv) * Scan forward to find the first character. */ if ((*p == *ustring1) && - (Tcl_UniCharNcmp(ustring1, p, + (TclUniCharNcmp(ustring1, p, (unsigned long) length1) == 0)) { match = p - ustring2; break; diff --git a/generic/tclExecute.c b/generic/tclExecute.c index bbe2728..4658711 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclExecute.c,v 1.54 2002/05/29 09:09:57 hobbs Exp $ + * RCS: @(#) $Id: tclExecute.c,v 1.55 2002/05/29 10:35:45 dkf Exp $ */ #include "tclInt.h" @@ -2751,7 +2751,7 @@ TclExecuteByteCode(interp, codePtr) Tcl_UniChar *uni1, *uni2; uni1 = Tcl_GetUnicodeFromObj(valuePtr, &s1len); uni2 = Tcl_GetUnicodeFromObj(value2Ptr, &s2len); - iResult = Tcl_UniCharNcmp(uni1, uni2, + iResult = TclUniCharNcmp(uni1, uni2, (unsigned) ((s1len < s2len) ? s1len : s2len)); } else { /* diff --git a/generic/tclInt.h b/generic/tclInt.h index 3a94802..59da527 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclInt.h,v 1.88 2002/05/20 10:22:26 das Exp $ + * RCS: @(#) $Id: tclInt.h,v 1.89 2002/05/29 10:35:45 dkf Exp $ */ #ifndef _TCLINT @@ -2359,6 +2359,23 @@ extern Tcl_Mutex tclObjMutex; #define TclGetString(objPtr) \ ((objPtr)->bytes? (objPtr)->bytes : Tcl_GetString((objPtr))) +/* + *---------------------------------------------------------------- + * Macro used by the Tcl core to compare Unicode strings; this is + * more efficient on a big-endian machine, and not hurtful on a + * little-endian machine. + * The ANSI C "prototype" for this macro is: + * + * EXTERN int TclUniCharNcmp _ANSI_ARGS_((CONST Tcl_UniChar *cs, + * CONST Tcl_UniChar *ct, unsigned long n)); + *---------------------------------------------------------------- + */ +#ifdef TCL_OPTIMIZE_UNICODE_COMPARE +# define TclUniCharNcmp(cs,ct,n) memcmp((cs),(ct),(n)*sizeof(Tcl_UniChar)) +#else /* !TCL_OPTIMIZE_UNICODE_COMPARE */ +# define TclUniCharNcmp Tcl_UniCharNcmp +#endif /* TCL_OPTIMIZE_UNICODE_COMPARE */ + #include "tclIntDecls.h" # undef TCL_STORAGE_CLASS diff --git a/generic/tclUtf.c b/generic/tclUtf.c index 56dcaca..667bb6d 100644 --- a/generic/tclUtf.c +++ b/generic/tclUtf.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUtf.c,v 1.24 2002/05/29 09:09:57 hobbs Exp $ + * RCS: @(#) $Id: tclUtf.c,v 1.25 2002/05/29 10:35:46 dkf Exp $ */ #include "tclInt.h" @@ -1351,16 +1351,23 @@ Tcl_UniCharNcmp(cs, ct, n) CONST Tcl_UniChar *ct; /* Unicode string cs is compared to. */ unsigned long n; /* Number of unichars to compare. */ { +#ifdef TCL_OPTIMIZE_UNICODE_COMPARE /* - * We can't simply call 'memcmp(cs, ct, n*sizeof(Tcl_UniChar));' - * because that may not be lexically correct. + * We are definitely on a big-endian machine; memcmp() is safe */ - for ( ; n != 0; n--, cs++, ct++) { + return memcmp(cs, ct, n*sizeof(Tcl_UniChar)); + +#else /* !TCL_OPTIMIZE_UNICODE_COMPARE */ + /* + * We can't simply call memcmp() because that is not lexically correct. + */ + for ( ; n != 0; cs++, ct++, n--) { if (*cs != *ct) { return (*cs - *ct); } } return 0; +#endif /* TCL_OPTIMIZE_UNICODE_COMPARE */ } /* |