From 184957c0ed7fe924e8d2ce5384f97716d12efce9 Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Thu, 7 Mar 2024 12:24:03 -0500 Subject: [PATCH] Use `fwrite` and `fputs` instead of multiple `putc` --- src/asm/output.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/asm/output.cpp b/src/asm/output.cpp index bc5417e1..fb58a42f 100644 --- a/src/asm/output.cpp +++ b/src/asm/output.cpp @@ -43,18 +43,20 @@ static std::deque assertions; static std::deque fileStackNodes; // Write a long to a file (little-endian) -static void putlong(uint32_t i, FILE *f) { - putc(i, f); - putc(i >> 8, f); - putc(i >> 16, f); - putc(i >> 24, f); +static void putlong(uint32_t n, FILE *f) { + uint8_t bytes[] = { + (uint8_t)n, + (uint8_t)(n >> 8), + (uint8_t)(n >> 16), + (uint8_t)(n >> 24), + }; + fwrite(bytes, 1, sizeof(bytes), f); } // Write a NUL-terminated string to a file static void putstring(std::string const &s, FILE *f) { - for (char c : s) - putc(c, f); - putc(0, f); + fputs(s.c_str(), f); + putc('\0', f); } void out_RegisterNode(FileStackNode *node) {