diff options
author | Michael Drake <michael.drake@codethink.co.uk> | 2016-01-29 17:59:00 +0000 |
---|---|---|
committer | Michael Drake <michael.drake@codethink.co.uk> | 2016-01-29 17:59:00 +0000 |
commit | 4ef9aeab25b67fa27e951473c78f33a600503ee4 (patch) | |
tree | c0389726cf5768fbca23c458b05a38d3446c4475 | |
parent | 737cb995c1b2bf144ee5087a011418b1f9b8aa69 (diff) | |
parent | a37713d9b0d49e9996b6eba9789e6f4ace88cb85 (diff) | |
download | libdom-4ef9aeab25b67fa27e951473c78f33a600503ee4.tar.gz libdom-4ef9aeab25b67fa27e951473c78f33a600503ee4.tar.bz2 |
Merge branch 'tlsa/faster-strings'
-rw-r--r-- | src/core/string.c | 40 |
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) { |