From a21e641748523af9edc5d373fff8907ebcc7450a Mon Sep 17 00:00:00 2001 From: Velikiy Kirill Date: Mon, 28 Jul 2025 01:26:14 +0300 Subject: [PATCH] LinkedHashMap: Fix head being null when initializing from map (#2334) * LinkedHashMap: Fix head being null when initializing from map --- lib/std/collections/linked_hashmap.c3 | 15 +++++---------- test/unit/stdlib/collections/linked_map.c3 | 1 + 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/std/collections/linked_hashmap.c3 b/lib/std/collections/linked_hashmap.c3 index d5891e0cb..f44f6c209 100644 --- a/lib/std/collections/linked_hashmap.c3 +++ b/lib/std/collections/linked_hashmap.c3 @@ -158,9 +158,9 @@ fn LinkedHashMap* LinkedHashMap.tinit_from_map(&map, LinkedHashMap* other_map) return map.init_from_map(tmem, other_map) @inline; } -fn bool LinkedHashMap.is_empty(&map) @inline +fn bool LinkedHashMap.is_empty(&map) @inline { - return !map.count; + return !map.count; } fn usz LinkedHashMap.len(&map) @inline => map.count; @@ -533,14 +533,9 @@ fn void LinkedHashMap.transfer(&map, LinkedEntry*[] new_table) @private fn void LinkedHashMap.put_all_for_create(&map, LinkedHashMap* other_map) @private { if (!other_map.count) return; - foreach (LinkedEntry *e : other_map.table) - { - while (e) - { - map.put_for_create(e.key, e.value); - e = e.next; - } - } + other_map.@each(; Key key, Value value) { + map.set(key, value); + }; } fn void LinkedHashMap.put_for_create(&map, Key key, Value value) @private diff --git a/test/unit/stdlib/collections/linked_map.c3 b/test/unit/stdlib/collections/linked_map.c3 index 388eecc36..fab9be24f 100644 --- a/test/unit/stdlib/collections/linked_map.c3 +++ b/test/unit/stdlib/collections/linked_map.c3 @@ -136,6 +136,7 @@ fn void linked_map_copy() assert(key == expected_order[index]); index++; }; + assert(index == 3); // check if @each worked } fn void linked_map_iterators()