From deeaf5134dcd156500436ad57ba3d6e814a21849 Mon Sep 17 00:00:00 2001 From: batleram Date: Sat, 24 Oct 2026 17:28:26 -0400 Subject: Hardcode templating ~800ms --- calc.c | 59 ++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 17 deletions(-) (limited to 'calc.c') diff --git a/calc.c b/calc.c index 2f533b1..ddcfe95 100644 --- a/calc.c +++ b/calc.c @@ -1,4 +1,5 @@ #include "calc.h" +#include "itoa_lut.h" #include #include #include @@ -27,6 +28,25 @@ uint32_t subnetmask_for_netspace(unsigned int desired_netspace) { return start; } +void write_ip(char **chunk_ptr, uint32_t ip) { + // local ptr so we don't have to deref every time + char *ptr = *chunk_ptr; + LutEntry e = {.bits = itoa_lut[(ip >> 24) & 0xff]}; + WRITE_STR(ptr, e.fields.chars, e.fields.len) + ptr[0] = '.'; + ptr += 1; + e.bits = itoa_lut[(ip >> 16) & 0xff]; + WRITE_STR(ptr, e.fields.chars, e.fields.len) + ptr[0] = '.'; + ptr += 1; + e.bits = itoa_lut[(ip >> 8) & 0xff]; + WRITE_STR(ptr, e.fields.chars, e.fields.len) + ptr[0] = '.'; + ptr += 1; + e.bits = itoa_lut[ip & 0xff]; + WRITE_STR(ptr, e.fields.chars, e.fields.len) + *chunk_ptr = ptr; +} int main(int argc, char** argv) { struct timespec start; @@ -64,31 +84,36 @@ int main(int argc, char** argv) { fprintf(out, "[\n"); // file start uint32_t offset = 0; int i = 0; + char chunk[1024] = {0}; while (i