Skip to content

Instantly share code, notes, and snippets.

@cajlarsson
Last active August 29, 2015 14:19
Show Gist options
  • Save cajlarsson/ab33f66d40da17b89409 to your computer and use it in GitHub Desktop.
Save cajlarsson/ab33f66d40da17b89409 to your computer and use it in GitHub Desktop.
librcd split
#import "rcd.h"
#import "rio.h"
#pragma librcd
void rcd_main(list(fstr_t)* main_args, list(fstr_t)* main_env) {
rio_t* in = rio_stdin();
volatile size_t lines = 0;
fstr_t line_tail;
uint128_t before = rio_epoch_ns_now();
fstr_t buffer = fss(fstr_alloc_buffer(PAGE_SIZE*1000));
volatile size_t words = 0;
try {
for(;;) {
line_tail = rio_read_to_separator(in, "\n", buffer);
lines++;
fstr_t word;
while (fstr_iterate(&line_tail, " ", &word))
if (word.len > 0)
words++;
}
} catch(exception_io, e);
uint128_t after = rio_epoch_ns_now();
rio_debug(concs("saw ", lines, " lines and ", words , " words in ", after - before, "ns.\n"));
lwt_exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment