From 748e48b1e979ced26c2348642adf7b05a6564b2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Mon, 15 Jul 2024 14:51:39 +0200 Subject: [PATCH 1/3] Avoid copying HashMap table entries during iteration. --- source/vibe/container/hashmap.d | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/source/vibe/container/hashmap.d b/source/vibe/container/hashmap.d index 64d337f..43a3167 100644 --- a/source/vibe/container/hashmap.d +++ b/source/vibe/container/hashmap.d @@ -257,15 +257,15 @@ struct HashMap(TKey, TValue, Traits = DefaultHashMapTraits!TKey, Allocator = IAl return 0; } - auto byKey() { return bySlot.map!(e => e.key); } - auto byKey() const { return bySlot.map!(e => e.key); } - auto byValue() { return bySlot.map!(e => e.value); } - auto byValue() const { return bySlot.map!(e => e.value); } - auto byKeyValue() { import std.typecons : Tuple; return bySlot.map!(e => Tuple!(Key, "key", Value, "value")(e.key, e.value)); } - auto byKeyValue() const { import std.typecons : Tuple; return bySlot.map!(e => Tuple!(const(Key), "key", const(Value), "value")(e.key, e.value)); } - - private auto bySlot() { return m_table[].filter!(e => !Traits.equals(e.key, Traits.clearValue)); } - private auto bySlot() const { return m_table[].filter!(e => !Traits.equals(e.key, Traits.clearValue)); } + auto byKey() { return bySlot.map!((ref e) => e.key); } + auto byKey() const { return bySlot.map!((ref e) => e.key); } + auto byValue() { return bySlot.map!((ref e) => e.value); } + auto byValue() const { return bySlot.map!((ref e) => e.value); } + auto byKeyValue() { import std.typecons : Tuple; return bySlot.map!((ref e) => Tuple!(Key, "key", Value, "value")(e.key, e.value)); } + auto byKeyValue() const { import std.typecons : Tuple; return bySlot.map!((ref e) => Tuple!(const(Key), "key", const(Value), "value")(e.key, e.value)); } + + private auto bySlot() { return m_table[].filter!((ref e) => !Traits.equals(e.key, Traits.clearValue)); } + private auto bySlot() const { return m_table[].filter!((ref e) => !Traits.equals(e.key, Traits.clearValue)); } private @property AllocatorInstanceType allocator() { From 01c1b515c00568806d8b27ba75b3dd985f0bc02e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Mon, 15 Jul 2024 15:36:31 +0200 Subject: [PATCH 2/3] Use macOS 13 CI runner. --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8ed7498..d851484 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macOS-latest] + os: [ubuntu-latest, windows-latest, macOS-13] dc: [dmd-latest, ldc-latest] arch: [x86_64] tests: [unittests] From e58f8d2b699ee01eef9a9ca2e2968bc3e5ee3d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Mon, 15 Jul 2024 16:55:56 +0200 Subject: [PATCH 3/3] Let HashMap.byValue return elements by ref. --- source/vibe/container/hashmap.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/vibe/container/hashmap.d b/source/vibe/container/hashmap.d index 43a3167..a8b85cb 100644 --- a/source/vibe/container/hashmap.d +++ b/source/vibe/container/hashmap.d @@ -259,8 +259,8 @@ struct HashMap(TKey, TValue, Traits = DefaultHashMapTraits!TKey, Allocator = IAl auto byKey() { return bySlot.map!((ref e) => e.key); } auto byKey() const { return bySlot.map!((ref e) => e.key); } - auto byValue() { return bySlot.map!((ref e) => e.value); } - auto byValue() const { return bySlot.map!((ref e) => e.value); } + auto byValue() { return bySlot.map!(ref(ref e) => e.value); } + auto byValue() const { return bySlot.map!(ref(ref e) => e.value); } auto byKeyValue() { import std.typecons : Tuple; return bySlot.map!((ref e) => Tuple!(Key, "key", Value, "value")(e.key, e.value)); } auto byKeyValue() const { import std.typecons : Tuple; return bySlot.map!((ref e) => Tuple!(const(Key), "key", const(Value), "value")(e.key, e.value)); }