From bd607b131ee35c89a4673dda60b58355931d12d4 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sat, 27 Mar 2021 12:13:17 +0000 Subject: [PATCH] Fix #882 --- src/ir_print.cpp | 50 +++++++++++++----------------------------------- 1 file changed, 13 insertions(+), 37 deletions(-) diff --git a/src/ir_print.cpp b/src/ir_print.cpp index d6b387de1..49f0bafba 100644 --- a/src/ir_print.cpp +++ b/src/ir_print.cpp @@ -148,41 +148,29 @@ void ir_print_escape_string(irFileBuffer *f, String name, bool print_quotes, boo } char const hex_table[] = "0123456789ABCDEF"; - isize buf_len = name.len + extra + 2 + 1; - - gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&string_buffer_arena); - - u8 *buf = gb_alloc_array(string_buffer_allocator, u8, buf_len); - - isize j = 0; if (print_quotes) { - buf[j++] = '"'; + ir_write_byte(f, '"'); } if (prefix_with_dot) { - buf[j++] = '.'; + ir_write_byte(f, '.'); } for (isize i = 0; i < name.len; i++) { u8 c = name[i]; if (ir_valid_char(c)) { - buf[j++] = c; + ir_write_byte(f, c); } else { - buf[j] = '\\'; - buf[j+1] = hex_table[c >> 4]; - buf[j+2] = hex_table[c & 0x0f]; - j += 3; + ir_write_byte(f, '\\'); + ir_write_byte(f, hex_table[c >> 4]); + ir_write_byte(f, hex_table[c & 0x0f]); } } if (print_quotes) { - buf[j++] = '"'; + ir_write_byte(f, '"'); } - - ir_file_write(f, buf, j); - - gb_temp_arena_memory_end(tmp); } @@ -201,32 +189,20 @@ void ir_print_escape_path(irFileBuffer *f, String path) { } - char hex_table[] = "0123456789ABCDEF"; - isize buf_len = path.len + extra + 2 + 1; - - gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&string_buffer_arena); - - u8 *buf = gb_alloc_array(string_buffer_allocator, u8, buf_len); - - isize j = 0; + char const hex_table[] = "0123456789ABCDEF"; for (isize i = 0; i < path.len; i++) { u8 c = path[i]; if (ir_valid_char(c) || c == ':') { - buf[j++] = c; + ir_write_byte(f, c); } else if (c == '\\') { - buf[j++] = '/'; + ir_write_byte(f, '/'); } else { - buf[j] = '\\'; - buf[j+1] = hex_table[c >> 4]; - buf[j+2] = hex_table[c & 0x0f]; - j += 3; + ir_write_byte(f, '\\'); + ir_write_byte(f, hex_table[c >> 4]); + ir_write_byte(f, hex_table[c & 0x0f]); } } - - ir_file_write(f, buf, j); - - gb_temp_arena_memory_end(tmp); }