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>2022-01-13 15:33:54 -0500
commit3bf99421c04fdcc789745b7c59fc9bee8edce06b (patch)
treebdd67c76a8a00e48f89b82088cc8a8ce1329a54d /src/node.c
parent16e8c50a29d8a932fa84a74d0b2a732994116db0 (diff)
downloadserd-3bf99421c04fdcc789745b7c59fc9bee8edce06b.tar.gz
serd-3bf99421c04fdcc789745b7c59fc9bee8edce06b.tar.bz2
serd-3bf99421c04fdcc789745b7c59fc9bee8edce06b.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 3b125d66..c444546d 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>
@@ -74,10 +73,9 @@ serd_node_from_string(const SerdType type, const uint8_t* const 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;
}
@@ -90,11 +88,9 @@ serd_node_from_substring(const SerdType type,
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;
}
@@ -117,7 +113,6 @@ serd_node_equals(const SerdNode* const a, const SerdNode* const 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)));
}
@@ -246,13 +241,12 @@ serd_node_new_uri(const SerdURI* const uri,
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
@@ -270,14 +264,13 @@ serd_node_new_relative_uri(const SerdURI* const 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
@@ -303,7 +296,7 @@ serd_node_new_decimal(const double d, const 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
@@ -326,7 +319,7 @@ serd_node_new_decimal(const double d, const 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;
@@ -336,7 +329,7 @@ serd_node_new_decimal(const double d, const 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) {
@@ -354,7 +347,7 @@ serd_node_new_integer(const 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;
@@ -363,7 +356,7 @@ serd_node_new_integer(const 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 {
@@ -380,12 +373,11 @@ serd_node_new_blob(const void* const buf,
{
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;
}