summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2003-09-04 23:03:58 +0000
committerJeremy Allison <jra@samba.org>2003-09-04 23:03:58 +0000
commit0e8c2a4133158b59426ec0b260e97d1dacf98e73 (patch)
tree455d0e52f8d8849bcec1bdd3797281c0f58f8dfe /source3
parentbf0f3be29dc04f51ebf18425abb41979fdb7897a (diff)
downloadsamba-0e8c2a4133158b59426ec0b260e97d1dacf98e73.tar.gz
samba-0e8c2a4133158b59426ec0b260e97d1dacf98e73.tar.bz2
samba-0e8c2a4133158b59426ec0b260e97d1dacf98e73.zip
More hand-tuning of the fastpath. Don't do strlen() when we're doing
to walk to the end anyway. Jeremy. (This used to be commit 467cafdb1f7ddfb4278824f385b732975246a4f5)
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/charcnv.c39
-rw-r--r--source3/param/loadparm.c6
2 files changed, 31 insertions, 14 deletions
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index 080da8a690..a07ff7399d 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -240,18 +240,14 @@ static size_t convert_string_internal(charset_t from, charset_t to,
*
* Ensure the srclen contains the terminating zero.
*
+ * This function has been hand-tuned to provide a fast path.
+ * Don't change unless you really know what you are doing. JRA.
**/
size_t convert_string(charset_t from, charset_t to,
void const *src, size_t srclen,
void *dest, size_t destlen)
{
- if (srclen == (size_t)-1) {
- if (from == CH_UCS2)
- srclen = strlen_w(src)+2;
- else
- srclen = strlen(src)+1;
- }
if (srclen == 0)
return 0;
@@ -265,12 +261,17 @@ size_t convert_string(charset_t from, charset_t to,
while (srclen && destlen) {
if ((lastp = *p) <= 0x7f) {
*q++ = *p++;
- srclen--;
+ if (srclen != (size_t)-1) {
+ srclen--;
+ }
destlen--;
retval++;
if (!lastp)
break;
} else {
+ if (srclen == (size_t)-1) {
+ srclen = strlen(src)+1;
+ }
return retval + convert_string_internal(from, to, p, srclen, q, destlen);
}
}
@@ -285,13 +286,18 @@ size_t convert_string(charset_t from, charset_t to,
while ((srclen >= 2) && destlen) {
if ((lastp = *p) <= 0x7f && p[1] == 0) {
*q++ = *p;
- srclen -= 2;
+ if (srclen != (size_t)-1) {
+ srclen -= 2;
+ }
p += 2;
destlen--;
retval++;
if (!lastp)
break;
} else {
+ if (srclen == (size_t)-1) {
+ srclen = strlen_w(src)+2;
+ }
return retval + convert_string_internal(from, to, p, srclen, q, destlen);
}
}
@@ -307,12 +313,17 @@ size_t convert_string(charset_t from, charset_t to,
if ((lastp = *p) <= 0x7F) {
*q++ = *p++;
*q++ = '\0';
- srclen--;
+ if (srclen != (size_t)-1) {
+ srclen--;
+ }
destlen -= 2;
retval += 2;
if (!lastp)
break;
} else {
+ if (srclen == (size_t)-1) {
+ srclen = strlen(src)+1;
+ }
return retval + convert_string_internal(from, to, p, srclen, q, destlen);
}
}
@@ -697,22 +708,26 @@ size_t pull_ascii_nstring(char *dest, const void *src)
* @param dest_len is the maximum length allowed in the
* destination. If dest_len is -1 then no maxiumum is used.
**/
+
size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags)
{
size_t len=0;
- size_t src_len = strlen(src);
+ size_t src_len;
/* treat a pstring as "unlimited" length */
if (dest_len == (size_t)-1)
dest_len = sizeof(pstring);
if (flags & STR_TERMINATE)
- src_len++;
+ src_len = (size_t)-1;
+ else
+ src_len = strlen(src);
if (ucs2_align(base_ptr, dest, flags)) {
*(char *)dest = 0;
dest = (void *)((char *)dest + 1);
- if (dest_len) dest_len--;
+ if (dest_len)
+ dest_len--;
len++;
}
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index d672704c21..348abcc9e7 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -2717,8 +2717,10 @@ static BOOL handle_netbios_name(const char *pszParmValue, char **ptr)
static BOOL handle_charset(const char *pszParmValue, char **ptr)
{
- string_set(ptr, pszParmValue);
- init_iconv();
+ if (strcmp(*ptr, pszParmValue) != 0) {
+ string_set(ptr, pszParmValue);
+ init_iconv();
+ }
return True;
}