diff options
Diffstat (limited to 'src/node.c')
-rw-r--r-- | src/node.c | 34 |
1 files changed, 14 insertions, 20 deletions
@@ -37,10 +37,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; } @@ -51,11 +50,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; } @@ -79,7 +76,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))); @@ -209,13 +205,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 @@ -233,14 +228,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 @@ -266,7 +260,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 @@ -289,7 +283,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 = lround(frac_part * pow(10.0, (int)frac_digits)); s += frac_digits - 1; @@ -298,7 +292,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) { @@ -316,7 +310,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; @@ -325,7 +319,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 { @@ -361,7 +355,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); |