From 568ac13ff52199e36d83c4d8d14135ecd0ae3b42 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 23 Aug 2024 17:53:17 +0200 Subject: [PATCH] Optimize js_map_write, don't loop twice (#488) --- quickjs.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/quickjs.c b/quickjs.c index b7608f5..92b8969 100644 --- a/quickjs.c +++ b/quickjs.c @@ -46103,18 +46103,8 @@ static int js_map_write(BCWriterState *s, struct JSMapState *map_state, { struct list_head *el; JSMapRecord *mr; - uint32_t count; - - count = 0; - - if (map_state) { - list_for_each(el, &map_state->records) { - count++; - } - } - - bc_put_leb128(s, count); + bc_put_leb128(s, map_state ? map_state->record_count : 0); if (map_state) { list_for_each(el, &map_state->records) { mr = list_entry(el, JSMapRecord, link);