aboutsummaryrefslogtreecommitdiffstats
path: root/src/node.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-03-15 23:37:09 -0400
committerDavid Robillard <d@drobilla.net>2021-03-07 15:32:23 -0500
commita35d0782c0fb5a52d77dede6b0bffee4e7fdefbd (patch)
treef56a4f4b75361c9268ab2b58b1f0692a7bb2d32f /src/node.c
parenta7be33a7640ee51066c41eded5812d9cee5ad27e (diff)
downloadserd-a35d0782c0fb5a52d77dede6b0bffee4e7fdefbd.tar.gz
serd-a35d0782c0fb5a52d77dede6b0bffee4e7fdefbd.tar.bz2
serd-a35d0782c0fb5a52d77dede6b0bffee4e7fdefbd.zip
Remove useless character counting
Diffstat (limited to 'src/node.c')
-rw-r--r--src/node.c36
1 files changed, 14 insertions, 22 deletions
diff --git a/src/node.c b/src/node.c
index 415b4031..7415ae36 100644
--- a/src/node.c
+++ b/src/node.c
@@ -21,7 +21,6 @@
#include "serd/serd.h"
-#include <assert.h>
#include <float.h>
#include <math.h>
#include <stdbool.h>
@@ -46,10 +45,9 @@ serd_node_from_string(SerdType type, const uint8_t* str)
return SERD_NODE_NULL;
}
- SerdNodeFlags 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};
+ SerdNodeFlags flags = 0;
+ const size_t n_bytes = serd_strlen(str, &flags);
+ const SerdNode ret = {str, n_bytes, flags, type};
return ret;
}
@@ -60,11 +58,9 @@ serd_node_from_substring(SerdType type, const uint8_t* str, const size_t len)
return SERD_NODE_NULL;
}
- SerdNodeFlags 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};
+ SerdNodeFlags flags = 0;
+ const size_t n_bytes = serd_substrlen(str, len, &flags);
+ const SerdNode ret = {str, n_bytes, flags, type};
return ret;
}
@@ -87,7 +83,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)));
}
@@ -242,13 +237,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
@@ -266,14 +260,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
@@ -299,7 +292,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
@@ -322,7 +315,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 = (size_t)(s - buf);
+ node.n_bytes = (size_t)(s - buf);
} else {
uint64_t frac = (uint64_t)llround(frac_part * pow(10.0, (int)frac_digits));
s += frac_digits - 1;
@@ -332,7 +325,7 @@ serd_node_new_decimal(double d, unsigned frac_digits)
for (; i < frac_digits - 1 && !(frac % 10); ++i, --s, frac /= 10) {
}
- node.n_bytes = node.n_chars = (size_t)(s - buf) + 1u;
+ node.n_bytes = (size_t)(s - buf) + 1u;
// Write digits from last trailing zero to decimal point
for (; i < frac_digits; ++i) {
@@ -350,7 +343,7 @@ serd_node_new_integer(int64_t i)
uint64_t abs_i = (i < 0) ? -i : i;
const unsigned digits = serd_digits((double)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;
@@ -359,7 +352,7 @@ serd_node_new_integer(int64_t i)
++s;
}
- node.n_bytes = node.n_chars = (size_t)(s - buf) + 1u;
+ node.n_bytes = (size_t)(s - buf) + 1u;
// Write integer part (right to left)
do {
@@ -374,12 +367,11 @@ serd_node_new_blob(const void* buf, size_t size, bool wrap_lines)
{
const size_t len = serd_base64_get_length(size, wrap_lines);
uint8_t* str = (uint8_t*)calloc(len + 2, 1);
- SerdNode node = {str, len, len, 0, SERD_LITERAL};
+ SerdNode node = {str, len, 0, SERD_LITERAL};
if (serd_base64_encode(str, buf, size, wrap_lines)) {
node.flags |= SERD_HAS_NEWLINE;
}
-
return node;
}