aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-08-13 20:31:57 -0400
committerDavid Robillard <d@drobilla.net>2022-01-28 21:57:07 -0500
commit0e739f34801ff6810064a8fac570f6be2b61ae70 (patch)
tree4451739f8e9b00d490d2d59aa6b1f370ae99c356 /tools
parent63e7e57237a79d0447b0450a7fd3148c43052299 (diff)
downloadserd-0e739f34801ff6810064a8fac570f6be2b61ae70.tar.gz
serd-0e739f34801ff6810064a8fac570f6be2b61ae70.tar.bz2
serd-0e739f34801ff6810064a8fac570f6be2b61ae70.zip
Simplify output stream API
This makes the paging mechanism an internal detail once again. While it's conceptually elegant to simply have a single write interface and have the block dumper just be another implementation of that, unfortunately it is not practical. The inlining of serd_block_dumper_write() is a significant performance boost, because it avoids a non-inlinable function call of overhead per character. Compared to the SerdByteSink approach, this removes the burden and overhead of needing to dynamically allocate the structure itself.
Diffstat (limited to 'tools')
-rw-r--r--tools/console.c23
-rw-r--r--tools/console.h12
-rw-r--r--tools/serd-filter.c2
-rw-r--r--tools/serd-pipe.c2
-rw-r--r--tools/serd-sort.c2
5 files changed, 21 insertions, 20 deletions
diff --git a/tools/console.c b/tools/console.c
index d7f67c35..5cfeb56c 100644
--- a/tools/console.c
+++ b/tools/console.c
@@ -39,7 +39,8 @@ serd_tool_setup(SerdTool* const tool,
{
// Open the output first, since if that fails we have nothing to do
const char* const out_path = options.out_filename;
- if (!(tool->out = serd_open_output(out_path, options.block_size))) {
+
+ if (!((tool->out = serd_open_output(out_path)).stream)) {
fprintf(stderr,
"%s: failed to open output file (%s)\n",
program,
@@ -57,7 +58,8 @@ serd_tool_setup(SerdTool* const tool,
tool->world, options.output, options.out_filename, SERD_NQUADS),
options.output.flags,
tool->env,
- tool->out))) {
+ &tool->out,
+ options.block_size))) {
fprintf(stderr, "%s: failed to set up writing environment\n", program);
return SERD_ERR_INTERNAL;
}
@@ -66,12 +68,12 @@ serd_tool_setup(SerdTool* const tool,
}
SerdStatus
-serd_tool_cleanup(const SerdTool tool)
+serd_tool_cleanup(SerdTool tool)
{
SerdStatus st = SERD_SUCCESS;
- if (tool.out) {
+ if (tool.out.stream) {
// Close the output stream explicitly to check if there were any errors
- if (serd_byte_sink_close(tool.out)) {
+ if (serd_close_output(&tool.out)) {
perror("write error");
st = SERD_ERR_BAD_WRITE;
}
@@ -80,7 +82,6 @@ serd_tool_cleanup(const SerdTool tool)
serd_writer_free(tool.writer);
serd_env_free(tool.env);
serd_world_free(tool.world);
- serd_byte_sink_free(tool.out);
return st;
}
@@ -371,16 +372,16 @@ serd_open_input(const char* const filename, const size_t block_size)
return byte_source;
}
-SerdByteSink*
-serd_open_output(const char* const filename, const size_t block_size)
+SerdOutputStream
+serd_open_output(const char* const filename)
{
if (!filename || !strcmp(filename, "-")) {
serd_set_stream_utf8_mode(stdout);
- return serd_byte_sink_new_function(
- (SerdWriteFunc)fwrite, (SerdStreamCloseFunc)fclose, stdout, 1);
+ return serd_open_output_stream(
+ (SerdWriteFunc)fwrite, (SerdStreamCloseFunc)fclose, stdout);
}
- return serd_byte_sink_new_filename(filename, block_size);
+ return serd_open_output_file(filename);
}
SerdStatus
diff --git a/tools/console.h b/tools/console.h
index cb227e8e..97251f68 100644
--- a/tools/console.h
+++ b/tools/console.h
@@ -47,10 +47,10 @@ typedef struct {
// Common "global" state of a command-line tool that writes data
typedef struct {
- SerdByteSink* out;
- SerdWorld* world;
- SerdEnv* env;
- SerdWriter* writer;
+ SerdOutputStream out;
+ SerdWorld* world;
+ SerdEnv* env;
+ SerdWriter* writer;
} SerdTool;
static inline bool
@@ -122,8 +122,8 @@ serd_choose_syntax(SerdWorld* world,
SerdByteSource*
serd_open_input(const char* filename, size_t block_size);
-SerdByteSink*
-serd_open_output(const char* filename, size_t block_size);
+SerdOutputStream
+serd_open_output(const char* filename);
SerdStatus
serd_set_base_uri_from_path(SerdEnv* env, const char* path);
diff --git a/tools/serd-filter.c b/tools/serd-filter.c
index 6cf8e0e7..a6f9b484 100644
--- a/tools/serd-filter.c
+++ b/tools/serd-filter.c
@@ -123,7 +123,7 @@ log_error(SerdWorld* const world, const char* const fmt, ...)
static SerdStatus
run(Options opts)
{
- SerdTool app = {NULL, NULL, NULL, NULL};
+ SerdTool app = {{NULL, NULL, NULL}, NULL, NULL, NULL};
// Set up the writing environment
SerdStatus st = SERD_SUCCESS;
diff --git a/tools/serd-pipe.c b/tools/serd-pipe.c
index 57392c8a..08479a74 100644
--- a/tools/serd-pipe.c
+++ b/tools/serd-pipe.c
@@ -39,7 +39,7 @@ typedef struct {
static SerdStatus
run(const Options opts)
{
- SerdTool app = {NULL, NULL, NULL, NULL};
+ SerdTool app = {{NULL, NULL, NULL}, NULL, NULL, NULL};
// Set up the writing environment
SerdStatus st = SERD_SUCCESS;
diff --git a/tools/serd-sort.c b/tools/serd-sort.c
index bbdfa164..1018350d 100644
--- a/tools/serd-sort.c
+++ b/tools/serd-sort.c
@@ -57,7 +57,7 @@ input_has_graphs(const Options opts)
static SerdStatus
run(const Options opts)
{
- SerdTool app = {NULL, NULL, NULL, NULL};
+ SerdTool app = {{NULL, NULL, NULL}, NULL, NULL, NULL};
// Set up the writing environment
SerdStatus st = SERD_SUCCESS;