Optimize js_map_write, don't loop twice (#488)

This commit is contained in:
Ben Noordhuis 2024-08-23 17:53:17 +02:00 committed by GitHub
parent 4e52027fe7
commit 568ac13ff5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -46103,18 +46103,8 @@ static int js_map_write(BCWriterState *s, struct JSMapState *map_state,
{ {
struct list_head *el; struct list_head *el;
JSMapRecord *mr; 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) { if (map_state) {
list_for_each(el, &map_state->records) { list_for_each(el, &map_state->records) {
mr = list_entry(el, JSMapRecord, link); mr = list_entry(el, JSMapRecord, link);