replace unordered_map with map, less heap

This commit is contained in:
proddy
2026-01-22 16:40:05 +01:00
parent 038f06e59f
commit e0a26a38fa
7 changed files with 14 additions and 14 deletions

View File

@@ -19,7 +19,7 @@
#ifndef EMSESP_COMMAND_H_ #ifndef EMSESP_COMMAND_H_
#define EMSESP_COMMAND_H_ #define EMSESP_COMMAND_H_
#include <unordered_map> #include <map>
#include "console.h" #include "console.h"
#include <esp32-psram.h> #include <esp32-psram.h>
@@ -153,8 +153,8 @@ class Command {
class SUrlParser { class SUrlParser {
private: private:
std::unordered_map<std::string, std::string> m_keysvalues; std::map<std::string, std::string> m_keysvalues;
std::vector<std::string> m_folders; std::vector<std::string> m_folders;
public: public:
SUrlParser() = default; SUrlParser() = default;
@@ -166,7 +166,7 @@ class SUrlParser {
return m_folders; return m_folders;
}; };
std::unordered_map<std::string, std::string> & params() { std::map<std::string, std::string> & params() {
return m_keysvalues; return m_keysvalues;
}; };

View File

@@ -1720,8 +1720,8 @@ void EMSdevice::get_value_json(JsonObject json, DeviceValue & dv) {
// generate Prometheus metrics format from device values // generate Prometheus metrics format from device values
std::string EMSdevice::get_metrics_prometheus(const int8_t tag) { std::string EMSdevice::get_metrics_prometheus(const int8_t tag) {
std::string result; std::string result;
std::unordered_map<std::string, bool> seen_metrics; std::map<std::string, bool> seen_metrics;
// Helper function to check if a device value type is supported for Prometheus metrics // Helper function to check if a device value type is supported for Prometheus metrics
auto is_supported_type = [](uint8_t type) -> bool { auto is_supported_type = [](uint8_t type) -> bool {

View File

@@ -26,7 +26,7 @@
#include "emsdevicevalue.h" #include "emsdevicevalue.h"
#include <esp32-psram.h> #include <esp32-psram.h>
#include <unordered_map> #include <map>
namespace emsesp { namespace emsesp {

View File

@@ -24,7 +24,7 @@
#include <string> #include <string>
#include <functional> #include <functional>
#include <deque> #include <deque>
#include <unordered_map> #include <map>
#include <list> #include <list>
#include <ArduinoJson.h> #include <ArduinoJson.h>

View File

@@ -20,7 +20,7 @@
#define EMSESP_EMSFACTORY_H_ #define EMSESP_EMSFACTORY_H_
#include <memory> // for unique_ptr #include <memory> // for unique_ptr
#include <unordered_map> #include <map>
// Forward declaration // Forward declaration
namespace emsesp { namespace emsesp {
@@ -45,7 +45,7 @@ class EMSFactory {
reg[device_type] = factory; reg[device_type] = factory;
} }
using FactoryMap = std::unordered_map<uint8_t, EMSFactory *>; using FactoryMap = std::map<uint8_t, EMSFactory *>;
// returns all registered classes (really only for debugging) // returns all registered classes (really only for debugging)
static auto device_handlers() -> const FactoryMap & { static auto device_handlers() -> const FactoryMap & {
@@ -76,7 +76,7 @@ class EMSFactory {
static auto makeRaw(const uint8_t device_type, uint8_t device_id, uint8_t product_id, const char * version, const char * name, uint8_t flags, uint8_t brand) static auto makeRaw(const uint8_t device_type, uint8_t device_id, uint8_t product_id, const char * version, const char * name, uint8_t flags, uint8_t brand)
-> EMSdevice * { -> EMSdevice * {
auto & reg = EMSFactory::getRegister(); auto & reg = EMSFactory::getRegister();
auto it = reg.find(device_type); auto it = reg.find(device_type);
if (it != reg.end()) { if (it != reg.end()) {
return it->second->construct(device_type, device_id, product_id, version, name, flags, brand); return it->second->construct(device_type, device_id, product_id, version, name, flags, brand);
} }

View File

@@ -1761,8 +1761,8 @@ void System::get_value_json(JsonObject output, const std::string & circuit, cons
// generate Prometheus metrics format from system values // generate Prometheus metrics format from system values
std::string System::get_metrics_prometheus() { std::string System::get_metrics_prometheus() {
std::string result; std::string result;
std::unordered_map<std::string, bool> seen_metrics; std::map<std::string, bool> seen_metrics;
result.reserve(16000); result.reserve(16000);

View File

@@ -68,7 +68,7 @@ class Connect : public EMSdevice {
bool set_childlock(const char * value, const int8_t id); bool set_childlock(const char * value, const int8_t id);
bool set_icon(const char * value, const int8_t id); bool set_icon(const char * value, const int8_t id);
std::vector<std::shared_ptr<Connect::RoomCircuit>> room_circuits_; std::vector<std::shared_ptr<Connect::RoomCircuit>, AllocatorPSRAM<std::shared_ptr<Connect::RoomCircuit>>> room_circuits_;
void process_OutdoorTemp(std::shared_ptr<const Telegram> telegram); void process_OutdoorTemp(std::shared_ptr<const Telegram> telegram);
void process_RCTime(std::shared_ptr<const Telegram> telegram); void process_RCTime(std::shared_ptr<const Telegram> telegram);