diff options
author | dgp <dgp@users.sourceforge.net> | 2009-02-13 03:22:51 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2009-02-13 03:22:51 (GMT) |
commit | f819f7990a8794c9429eb83b8f912950b85d0a91 (patch) | |
tree | 9f47ca210d9c3fa3b8d6fe297252cc4cded4ecc6 /generic/tclInt.h | |
parent | ebd799b7e4d40a843ff6c49f8fc77670acf6b67a (diff) | |
download | tcl-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.h | 27 |
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 |