diff options
author | David Robillard <d@drobilla.net> | 2016-03-15 23:37:09 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-11-25 09:21:03 +0100 |
commit | d70d76deeb5735f97bb90792d5200ee812fb50b0 (patch) | |
tree | 45704de9956c4e96db0dfd686d94876b720cb96b /src/node.c | |
parent | f046eb982627f344fc0eeff6be82028318862e67 (diff) | |
download | serd-d70d76deeb5735f97bb90792d5200ee812fb50b0.tar.gz serd-d70d76deeb5735f97bb90792d5200ee812fb50b0.tar.bz2 serd-d70d76deeb5735f97bb90792d5200ee812fb50b0.zip |
Remove useless character counting
Diffstat (limited to 'src/node.c')
-rw-r--r-- | src/node.c | 34 |
1 files changed, 14 insertions, 20 deletions
@@ -38,10 +38,9 @@ serd_node_from_string(SerdType type, const uint8_t* str) return SERD_NODE_NULL; } - uint32_t flags = 0; - size_t buf_n_bytes = 0; - const size_t buf_n_chars = serd_strlen(str, &buf_n_bytes, &flags); - SerdNode ret = { str, buf_n_bytes, buf_n_chars, flags, type }; + uint32_t flags = 0; + const size_t n_bytes = serd_strlen(str, &flags); + const SerdNode ret = { str, n_bytes, flags, type }; return ret; } @@ -52,11 +51,9 @@ serd_node_from_substring(SerdType type, const uint8_t* str, const size_t len) return SERD_NODE_NULL; } - uint32_t flags = 0; - size_t buf_n_bytes = 0; - const size_t buf_n_chars = serd_substrlen(str, len, &buf_n_bytes, &flags); - assert(buf_n_bytes <= len); - SerdNode ret = { str, buf_n_bytes, buf_n_chars, flags, type }; + uint32_t flags = 0; + const size_t n_bytes = serd_substrlen(str, len, &flags); + const SerdNode ret = { str, n_bytes, flags, type }; return ret; } @@ -80,7 +77,6 @@ serd_node_equals(const SerdNode* a, const SerdNode* b) return (a == b) || (a->type == b->type && a->n_bytes == b->n_bytes - && a->n_chars == b->n_chars && ((a->buf == b->buf) || !memcmp((const char*)a->buf, (const char*)b->buf, a->n_bytes + 1))); @@ -210,13 +206,12 @@ serd_node_new_uri(const SerdURI* uri, const SerdURI* base, SerdURI* out) const size_t len = serd_uri_string_length(&abs_uri); uint8_t* buf = (uint8_t*)malloc(len + 1); - SerdNode node = { buf, 0, 0, 0, SERD_URI }; + SerdNode node = { buf, len, 0, SERD_URI }; uint8_t* ptr = buf; const size_t actual_len = serd_uri_serialise(&abs_uri, string_sink, &ptr); buf[actual_len] = '\0'; node.n_bytes = actual_len; - node.n_chars = serd_strlen(buf, NULL, NULL); if (out) { serd_uri_parse(buf, out); // TODO: cleverly avoid double parse @@ -234,14 +229,13 @@ serd_node_new_relative_uri(const SerdURI* uri, const size_t uri_len = serd_uri_string_length(uri); const size_t base_len = serd_uri_string_length(base); uint8_t* buf = (uint8_t*)malloc(uri_len + base_len + 1); - SerdNode node = { buf, 0, 0, 0, SERD_URI }; + SerdNode node = { buf, 0, 0, SERD_URI }; uint8_t* ptr = buf; const size_t actual_len = serd_uri_serialise_relative( uri, base, root, string_sink, &ptr); buf[actual_len] = '\0'; node.n_bytes = actual_len; - node.n_chars = serd_strlen(buf, NULL, NULL); if (out) { serd_uri_parse(buf, out); // TODO: cleverly avoid double parse @@ -267,7 +261,7 @@ serd_node_new_decimal(double d, unsigned frac_digits) const double abs_d = fabs(d); const unsigned int_digits = serd_digits(abs_d); char* buf = (char*)calloc(int_digits + frac_digits + 3, 1); - SerdNode node = { (const uint8_t*)buf, 0, 0, 0, SERD_LITERAL }; + SerdNode node = { (const uint8_t*)buf, 0, 0, SERD_LITERAL }; const double int_part = floor(abs_d); // Point s to decimal point location @@ -290,7 +284,7 @@ serd_node_new_decimal(double d, unsigned frac_digits) double frac_part = fabs(d - int_part); if (frac_part < DBL_EPSILON) { *s++ = '0'; - node.n_bytes = node.n_chars = (s - buf); + node.n_bytes = (s - buf); } else { uint64_t frac = frac_part * pow(10.0, (int)frac_digits) + 0.5; s += frac_digits - 1; @@ -299,7 +293,7 @@ serd_node_new_decimal(double d, unsigned frac_digits) // Skip trailing zeros for (; i < frac_digits - 1 && !(frac % 10); ++i, --s, frac /= 10) {} - node.n_bytes = node.n_chars = (s - buf) + 1; + node.n_bytes = (s - buf) + 1; // Write digits from last trailing zero to decimal point for (; i < frac_digits; ++i) { @@ -317,7 +311,7 @@ serd_node_new_integer(int64_t i) int64_t abs_i = (i < 0) ? -i : i; const unsigned digits = serd_digits(abs_i); char* buf = (char*)calloc(digits + 2, 1); - SerdNode node = { (const uint8_t*)buf, 0, 0, 0, SERD_LITERAL }; + SerdNode node = { (const uint8_t*)buf, 0, 0, SERD_LITERAL }; // Point s to the end char* s = buf + digits - 1; @@ -326,7 +320,7 @@ serd_node_new_integer(int64_t i) ++s; } - node.n_bytes = node.n_chars = (s - buf) + 1; + node.n_bytes = (s - buf) + 1; // Write integer part (right to left) do { @@ -362,7 +356,7 @@ serd_node_new_blob(const void* buf, size_t size, bool wrap_lines) { const size_t len = (size + 2) / 3 * 4 + (wrap_lines * ((size - 1) / 57)); uint8_t* str = (uint8_t*)calloc(len + 2, 1); - SerdNode node = { str, len, len, 0, SERD_LITERAL }; + SerdNode node = { str, len, 0, SERD_LITERAL }; for (size_t i = 0, j = 0; i < size; i += 3, j += 4) { uint8_t in[4] = { 0, 0, 0, 0 }; size_t n_in = MIN(3, size - i); |