summaryrefslogtreecommitdiffstats
path: root/source3/lib/util_unistr.c
diff options
context:
space:
mode:
authorMartin Pool <mbp@samba.org>2003-04-04 08:16:14 +0000
committerMartin Pool <mbp@samba.org>2003-04-04 08:16:14 +0000
commit75438592cd8b427cbee4a55ee4bd2c8d15f6637d (patch)
treef0c4914dcd4a8347bc244812296104418850a2e7 /source3/lib/util_unistr.c
parentb5e7b9dbeadfd64e28e4b837222703b4060fb7f9 (diff)
downloadsamba-75438592cd8b427cbee4a55ee4bd2c8d15f6637d.tar.gz
samba-75438592cd8b427cbee4a55ee4bd2c8d15f6637d.tar.xz
samba-75438592cd8b427cbee4a55ee4bd2c8d15f6637d.zip
check_dos_char: Change this to use a lazily-initialized lookup table
indicating which characters are valid dos characters. This function was previously quite slow because it did two unicode conversions on every call. (This used to be commit e4ec19e03f95fb7d5b170c7e0ab5837ebc7dcd97)
Diffstat (limited to 'source3/lib/util_unistr.c')
-rw-r--r--source3/lib/util_unistr.c52
1 files changed, 49 insertions, 3 deletions
diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c
index 3f319eed81a..08bb03986f1 100644
--- a/source3/lib/util_unistr.c
+++ b/source3/lib/util_unistr.c
@@ -31,10 +31,21 @@ 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
-********************************************************************/
+
+/**
+ * Load or generate the case handling tables.
+ *
+ * The case tables are defined in UCS2 and don't depend on any
+ * configured parameters, so they never need to be reloaded.
+ **/
void load_case_tables(void)
{
static int initialised;
@@ -85,6 +96,16 @@ void load_case_tables(void)
*/
int check_dos_char(smb_ucs2_t c)
{
+ lazy_initialize_conv();
+
+ /* 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 +116,31 @@ 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.