Skip to content

Commit

Permalink
Tidy up and improve Vector class memory usage (#2558)
Browse files Browse the repository at this point in the history
This PR follows on from #2556 to reduce memory usage and performance when Vector is used with simple (scalar) values.
Additional tests added.
  • Loading branch information
mikee47 authored Sep 28, 2022
1 parent d21bf5a commit 34a796f
Show file tree
Hide file tree
Showing 5 changed files with 436 additions and 350 deletions.
12 changes: 11 additions & 1 deletion Sming/Wiring/WHashMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <iterator>
#include <cstdlib>
#include "WiringList.h"
#include "Print.h"

/**
* @brief HashMap class template
Expand Down Expand Up @@ -89,6 +90,15 @@ template <typename K, typename V> class HashMap
return &v;
}

size_t printTo(Print& p) const
{
size_t n{0};
n += p.print(k);
n += p.print(" = ");
n += p.print(v);
return n;
}

private:
const K& k;
Value& v;
Expand Down Expand Up @@ -285,7 +295,7 @@ template <typename K, typename V> class HashMap

bool allocate(unsigned int newSize)
{
return keys.allocate(newSize, K{}) && values.allocate(newSize, nil);
return keys.allocate(newSize) && values.allocate(newSize);
}

/**
Expand Down
Loading

0 comments on commit 34a796f

Please sign in to comment.