summaryrefslogtreecommitdiff
path: root/source3/lib/util_unistr.c
diff options
context:
space:
mode:
authorMartin Pool <mbp@samba.org>2003-04-08 03:01:02 +0000
committerMartin Pool <mbp@samba.org>2003-04-08 03:01:02 +0000
commit65289c353b77b31a746bcd36fb7fcbef01947187 (patch)
tree48bf199374987972c09cd0ee1b9bf421ff98f4d5 /source3/lib/util_unistr.c
parent38ec539cf5afeed3fe75f82e9aecbab7dc7f46ec (diff)
downloadsamba-65289c353b77b31a746bcd36fb7fcbef01947187.tar.gz
samba-65289c353b77b31a746bcd36fb7fcbef01947187.tar.bz2
samba-65289c353b77b31a746bcd36fb7fcbef01947187.zip
Merge from 3_0: Build a lookup table of valid DOS characters just
once, when init_iconv is first called. Use this in check_dos_char rather than doing the conversion every time. Much faster. (This used to be commit e8f1399323745a93ba9df97553effcf2d7629850)
Diffstat (limited to 'source3/lib/util_unistr.c')
-rw-r--r--source3/lib/util_unistr.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c
index c666155f9f..812859000a 100644
--- a/source3/lib/util_unistr.c
+++ b/source3/lib/util_unistr.c
@@ -31,6 +31,14 @@ static smb_ucs2_t *upcase_table;
static smb_ucs2_t *lowcase_table;
static uint8 *valid_table;
+/**
+ * This table says which Unicode characters are valid dos
+ * characters.
+ *
+ * Each value is just a single bit.
+ **/
+static uint8 doschar_table[8192]; /* 65536 characters / 8 bits/byte */
+
/*******************************************************************
load the case handling tables
@@ -85,6 +93,21 @@ void load_case_tables(void)
*/
static int check_dos_char(smb_ucs2_t c)
{
+ static int initialized = False;
+
+ if (!initialized) {
+ initialized = True;
+ init_doschar_table();
+ }
+
+ /* Find the right byte, and right bit within the byte; return
+ * 1 or 0 */
+ return (doschar_table[(c & 0xffff) / 8] & (1 << (c & 7))) != 0;
+}
+
+
+static int check_dos_char_slowly(smb_ucs2_t c)
+{
char buf[10];
smb_ucs2_t c2 = 0;
int len1, len2;
@@ -95,6 +118,31 @@ static int check_dos_char(smb_ucs2_t c)
return (c == c2);
}
+
+/**
+ * Fill out doschar table the hard way, by examining each character
+ **/
+void init_doschar_table(void)
+{
+ int i, j, byteval;
+
+ /* For each byte of packed table */
+
+ for (i = 0; i <= 0xffff; i += 8) {
+ byteval = 0;
+ for (j = 0; j <= 7; j++) {
+ smb_ucs2_t c;
+
+ c = i + j;
+
+ if (check_dos_char_slowly(c))
+ byteval |= 1 << j;
+ }
+ doschar_table[i/8] = byteval;
+ }
+}
+
+
/**
* Load the valid character map table from <tt>valid.dat</tt> or
* create from the configured codepage.