summaryrefslogtreecommitdiff
path: root/source3/lib/charcnv.c
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib/charcnv.c')
-rw-r--r--source3/lib/charcnv.c43
1 files changed, 32 insertions, 11 deletions
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index ceb9d57fc7..5a922e226c 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -511,22 +511,43 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen)
char *strdup_upper(const char *s)
{
- size_t size;
- wpstring buffer;
pstring out_buffer;
-
- size = convert_string(CH_UNIX, CH_UCS2, s, -1, buffer, sizeof(buffer));
- if (size == -1) {
- return NULL;
+ const unsigned char *p = (const unsigned char *)s;
+ unsigned char *q = (unsigned char *)out_buffer;
+
+ /* this is quite a common operation, so we want it to be
+ fast. We optimise for the ascii case, knowing that all our
+ supported multi-byte character sets are ascii-compatible
+ (ie. they match for the first 128 chars) */
+
+ while (1) {
+ if (*p & 0x80)
+ break;
+ *q++ = toupper(*p);
+ if (!*p)
+ break;
+ p++;
+ if (p - ( const unsigned char *)s >= sizeof(pstring))
+ break;
}
- strupper_w(buffer);
+ if (*p) {
+ /* MB case. */
+ size_t size;
+ wpstring buffer;
+ size = convert_string(CH_UNIX, CH_UCS2, s, -1, buffer, sizeof(buffer));
+ if (size == -1) {
+ return NULL;
+ }
+
+ strupper_w(buffer);
- size = convert_string(CH_UCS2, CH_UNIX, buffer, sizeof(buffer), out_buffer, sizeof(out_buffer));
- if (size == -1) {
- return NULL;
+ size = convert_string(CH_UCS2, CH_UNIX, buffer, sizeof(buffer), out_buffer, sizeof(out_buffer));
+ if (size == -1) {
+ return NULL;
+ }
}
-
+
return strdup(out_buffer);
}