summaryrefslogtreecommitdiffstats
path: root/generic/tclInt.h
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2009-02-13 03:22:51 (GMT)
committerdgp <dgp@users.sourceforge.net>2009-02-13 03:22:51 (GMT)
commitf819f7990a8794c9429eb83b8f912950b85d0a91 (patch)
tree9f47ca210d9c3fa3b8d6fe297252cc4cded4ecc6 /generic/tclInt.h
parentebd799b7e4d40a843ff6c49f8fc77670acf6b67a (diff)
downloadtcl-f819f7990a8794c9429eb83b8f912950b85d0a91.zip
tcl-f819f7990a8794c9429eb83b8f912950b85d0a91.tar.gz
tcl-f819f7990a8794c9429eb83b8f912950b85d0a91.tar.bz2
* generic/tclStringObj.c: Rewrites of the routines
Tcl_GetCharLength, Tcl_GetUniChar, Tcl_GetUnicodeFromObj, Tcl_GetRange, and TclStringObjReverse to use the new macro, and to more simply and clearly split the cases depending on whether a valid unicode rep is present or needs to be created. * generic/tclInt.h: New macro TclNumUtfChars meant to be a faster replacement for a full Tcl_NumUtfChars() call when the string has all single-byte characters.
Diffstat (limited to 'generic/tclInt.h')
-rw-r--r--generic/tclInt.h27
1 files changed, 26 insertions, 1 deletions
diff --git a/generic/tclInt.h b/generic/tclInt.h
index dba84fb..3de0ea2 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -15,7 +15,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.416 2009/02/03 18:48:25 dkf Exp $
+ * RCS: @(#) $Id: tclInt.h,v 1.417 2009/02/13 03:22:52 dgp Exp $
*/
#ifndef _TCLINT
@@ -3805,6 +3805,31 @@ MODULE_SCOPE void TclDbInitNewObj(Tcl_Obj *objPtr);
/*
*----------------------------------------------------------------
+ * Macro counterpart of the Tcl_NumUtfChars() function. To be used
+ * in speed-sensitive points where it pays to avoid a function call
+ * in the common case of counting along a string of all one-byte characters.
+ * The ANSI C "prototype" for this macro is:
+ *
+ * MODULE_SCOPE void TclNumUtfChars(int numChars, const char *bytes,
+ * int numBytes);
+ *----------------------------------------------------------------
+ */
+
+#define TclNumUtfChars(numChars, bytes, numBytes) \
+ do { \
+ int count, i = (numBytes); \
+ unsigned char *str = (unsigned char *) (bytes); \
+ while (i && (*str < 0xC0)) { i--; str++; } \
+ count = (numBytes) - i; \
+ if (i) { \
+ count += Tcl_NumUtfChars((bytes) + count, i); \
+ } \
+ (numChars) = count; \
+ } while (0);
+
+
+/*
+ *----------------------------------------------------------------
* Macro used by the Tcl core to compare Unicode strings. On big-endian
* systems we can use the more efficient memcmp, but this would not be
* lexically correct on little-endian systems. The ANSI C "prototype" for