diff options
author | David Robillard <d@drobilla.net> | 2018-10-28 14:15:28 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-03-08 23:23:05 -0500 |
commit | 6aee38ce233b319c4ee3ac1f16f4c2ca621cb4b0 (patch) | |
tree | 566321615dbbdc73554339c73da67a4bc0c02638 /src/writer.c | |
parent | 800f2d0d4960061a1739a36d8b608a13896b321e (diff) | |
download | serd-6aee38ce233b319c4ee3ac1f16f4c2ca621cb4b0.tar.gz serd-6aee38ce233b319c4ee3ac1f16f4c2ca621cb4b0.tar.bz2 serd-6aee38ce233b319c4ee3ac1f16f4c2ca621cb4b0.zip |
Cache commonly used nodes in the world
Diffstat (limited to 'src/writer.c')
-rw-r--r-- | src/writer.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/writer.c b/src/writer.c index 0fabb7af..4f4a76df 100644 --- a/src/writer.c +++ b/src/writer.c @@ -502,15 +502,13 @@ write_literal(SerdWriter* writer, const char* node_str = serd_node_string(node); const char* type_uri = datatype ? serd_node_string(datatype) : NULL; if (supports_abbrev(writer) && type_uri) { - if (!strncmp(type_uri, NS_XSD, sizeof(NS_XSD) - 1) && - (!strcmp(type_uri + sizeof(NS_XSD) - 1, "boolean") || - !strcmp(type_uri + sizeof(NS_XSD) - 1, "integer"))) { + if (serd_node_equals(datatype, writer->world->xsd_boolean) || + serd_node_equals(datatype, writer->world->xsd_integer)) { sink(node_str, node->n_bytes, writer); return true; } - if (!strncmp(type_uri, NS_XSD, sizeof(NS_XSD) - 1) && - !strcmp(type_uri + sizeof(NS_XSD) - 1, "decimal") && + if (serd_node_equals(datatype, writer->world->xsd_decimal) && strchr(node_str, '.') && node_str[node->n_bytes - 1] != '.') { /* xsd:decimal literals without trailing digits, e.g. "5.", can not be written bare in Turtle. We could add a 0 which is @@ -573,11 +571,12 @@ write_uri_node(SerdWriter* const writer, const char* node_str = serd_node_string(node); const bool has_scheme = serd_uri_string_has_scheme(node_str); if (supports_abbrev(writer)) { - if (field == SERD_PREDICATE && !strcmp(node_str, NS_RDF "type")) { + if (field == SERD_PREDICATE && + serd_node_equals(node, writer->world->rdf_type)) { return sink("a", 1, writer) == 1; } - if (!strcmp(node_str, NS_RDF "nil")) { + if (serd_node_equals(node, writer->world->rdf_type)) { return sink("()", 2, writer) == 2; } @@ -760,13 +759,13 @@ write_list_obj(SerdWriter* writer, const SerdNode* predicate, const SerdNode* object) { - if (!strcmp(serd_node_string(object), NS_RDF "nil")) { + if (serd_node_equals(object, writer->world->rdf_nil)) { --writer->indent; write_sep(writer, SEP_LIST_END); return true; } - if (!strcmp(serd_node_string(predicate), NS_RDF "first")) { + if (serd_node_equals(predicate, writer->world->rdf_first)) { write_sep(writer, SEP_LIST_SEP); write_node(writer, object, SERD_OBJECT, flags); } |