summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <michael.drake@codethink.co.uk>2016-01-29 17:38:09 +0000
committerMichael Drake <michael.drake@codethink.co.uk>2016-01-29 17:38:09 +0000
commita37713d9b0d49e9996b6eba9789e6f4ace88cb85 (patch)
tree1b1fc749c95788c0c512dec7fa9819fe640ef730
parente137aa0f31bcc399658d266487494ef07be185fc (diff)
downloadlibdom-a37713d9b0d49e9996b6eba9789e6f4ace88cb85.tar.gz
libdom-a37713d9b0d49e9996b6eba9789e6f4ace88cb85.tar.bz2
Optimise dom_string_(toupper|tolower) functions.
Since we don't support non-ascii strings here, the lpu calls to step though the characters was an unecessary overhead.
-rw-r--r--src/core/string.c40
1 files changed, 9 insertions, 31 deletions
diff --git a/src/core/string.c b/src/core/string.c
index d4c5cdf..9af2e74 100644
--- a/src/core/string.c
+++ b/src/core/string.c
@@ -935,8 +935,7 @@ dom_string_toupper(dom_string *source, bool ascii_only, dom_string **upper)
const uint8_t *orig_s = (const uint8_t *) dom_string_data(source);
const size_t nbytes = dom_string_byte_length(source);
uint8_t *copy_s;
- size_t index = 0, clen;
- parserutils_error err;
+ size_t index = 0;
dom_exception exc;
if (ascii_only == false)
@@ -948,21 +947,11 @@ dom_string_toupper(dom_string *source, bool ascii_only, dom_string **upper)
memcpy(copy_s, orig_s, nbytes);
while (index < nbytes) {
- err = parserutils_charset_utf8_char_byte_length(orig_s + index,
- &clen);
- if (err != PARSERUTILS_OK) {
- free(copy_s);
- /** \todo Find a better exception */
- return DOM_NO_MEM_ERR;
+ if (orig_s[index] >= 'a' && orig_s[index] <= 'z') {
+ copy_s[index] -= 'a' - 'A';
}
- if (clen == 1) {
- if (orig_s[index] >= 'a' &&
- orig_s[index] <= 'z')
- copy_s[index] -= 'a' - 'A';
- }
-
- index += clen;
+ index++;
}
if (((dom_string_internal*)source)->type == DOM_STRING_CDATA) {
@@ -992,8 +981,7 @@ dom_string_tolower(dom_string *source, bool ascii_only, dom_string **lower)
const uint8_t *orig_s = (const uint8_t *) dom_string_data(source);
const size_t nbytes = dom_string_byte_length(source);
uint8_t *copy_s;
- size_t index = 0, clen;
- parserutils_error err;
+ size_t index = 0;
dom_exception exc;
if (ascii_only == false)
@@ -1005,21 +993,11 @@ dom_string_tolower(dom_string *source, bool ascii_only, dom_string **lower)
memcpy(copy_s, orig_s, nbytes);
while (index < nbytes) {
- err = parserutils_charset_utf8_char_byte_length(orig_s + index,
- &clen);
- if (err != PARSERUTILS_OK) {
- free(copy_s);
- /** \todo Find a better exception */
- return DOM_NO_MEM_ERR;
- }
-
- if (clen == 1) {
- if (orig_s[index] >= 'A' &&
- orig_s[index] <= 'Z')
- copy_s[index] += 'a' - 'A';
+ if (orig_s[index] >= 'A' && orig_s[index] <= 'Z') {
+ copy_s[index] += 'a' - 'A';
}
-
- index += clen;
+
+ index++;
}
if (((dom_string_internal*)source)->type == DOM_STRING_CDATA) {