Skip to content

Commit f6ffae2

Browse files
authored
Merge pull request #13 from vibe-d/avoid_heasmap_table_entry_copy
Avoid copying HashMap table entries during iteration.
2 parents e26da4d + e58f8d2 commit f6ffae2

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
os: [ubuntu-latest, windows-latest, macOS-latest]
20+
os: [ubuntu-latest, windows-latest, macOS-13]
2121
dc: [dmd-latest, ldc-latest]
2222
arch: [x86_64]
2323
tests: [unittests]

source/vibe/container/hashmap.d

+9-9
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,15 @@ struct HashMap(TKey, TValue, Traits = DefaultHashMapTraits!TKey, Allocator = IAl
257257
return 0;
258258
}
259259

260-
auto byKey() { return bySlot.map!(e => e.key); }
261-
auto byKey() const { return bySlot.map!(e => e.key); }
262-
auto byValue() { return bySlot.map!(e => e.value); }
263-
auto byValue() const { return bySlot.map!(e => e.value); }
264-
auto byKeyValue() { import std.typecons : Tuple; return bySlot.map!(e => Tuple!(Key, "key", Value, "value")(e.key, e.value)); }
265-
auto byKeyValue() const { import std.typecons : Tuple; return bySlot.map!(e => Tuple!(const(Key), "key", const(Value), "value")(e.key, e.value)); }
266-
267-
private auto bySlot() { return m_table[].filter!(e => !Traits.equals(e.key, Traits.clearValue)); }
268-
private auto bySlot() const { return m_table[].filter!(e => !Traits.equals(e.key, Traits.clearValue)); }
260+
auto byKey() { return bySlot.map!((ref e) => e.key); }
261+
auto byKey() const { return bySlot.map!((ref e) => e.key); }
262+
auto byValue() { return bySlot.map!(ref(ref e) => e.value); }
263+
auto byValue() const { return bySlot.map!(ref(ref e) => e.value); }
264+
auto byKeyValue() { import std.typecons : Tuple; return bySlot.map!((ref e) => Tuple!(Key, "key", Value, "value")(e.key, e.value)); }
265+
auto byKeyValue() const { import std.typecons : Tuple; return bySlot.map!((ref e) => Tuple!(const(Key), "key", const(Value), "value")(e.key, e.value)); }
266+
267+
private auto bySlot() { return m_table[].filter!((ref e) => !Traits.equals(e.key, Traits.clearValue)); }
268+
private auto bySlot() const { return m_table[].filter!((ref e) => !Traits.equals(e.key, Traits.clearValue)); }
269269

270270
private @property AllocatorInstanceType allocator()
271271
{

0 commit comments

Comments
 (0)