Skip to content

Commit

Permalink
Merge pull request #13 from vibe-d/avoid_heasmap_table_entry_copy
Browse files Browse the repository at this point in the history
Avoid copying HashMap table entries during iteration.
  • Loading branch information
l-kramer authored Jul 15, 2024
2 parents e26da4d + e58f8d2 commit f6ffae2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
18 changes: 9 additions & 9 deletions source/vibe/container/hashmap.d
Original file line number Diff line number Diff line change
Expand Up @@ -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(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)); }

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()
{
Expand Down

0 comments on commit f6ffae2

Please sign in to comment.