mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-06-15 12:26:33 +03:00
order device values for packing, reducing stack
This commit is contained in:
@@ -38,21 +38,23 @@ DeviceValue::DeviceValue(uint8_t device_type,
|
|||||||
int16_t min,
|
int16_t min,
|
||||||
uint32_t max,
|
uint32_t max,
|
||||||
uint8_t state)
|
uint8_t state)
|
||||||
: device_type(device_type)
|
// Initializer list ordered to match the reordered field declarations in
|
||||||
, tag(tag)
|
// emsdevicevalue.h (pointers first, then 1-byte block, then 2/4-byte, then std::string)
|
||||||
, value_p(value_p)
|
: value_p(value_p)
|
||||||
, type(type)
|
|
||||||
, options(options)
|
|
||||||
, options_single(options_single)
|
|
||||||
, numeric_operator(numeric_operator)
|
|
||||||
, short_name(short_name)
|
, short_name(short_name)
|
||||||
, fullname(fullname)
|
, fullname(fullname)
|
||||||
, custom_fullname(custom_fullname)
|
, options(options)
|
||||||
|
, options_single(options_single)
|
||||||
|
, device_type(device_type)
|
||||||
|
, tag(tag)
|
||||||
|
, type(type)
|
||||||
|
, state(state)
|
||||||
|
, numeric_operator(numeric_operator)
|
||||||
, uom(uom)
|
, uom(uom)
|
||||||
, has_cmd(has_cmd)
|
, has_cmd(has_cmd)
|
||||||
, min(min)
|
, min(min)
|
||||||
, max(max)
|
, max(max)
|
||||||
, state(state) {
|
, custom_fullname(custom_fullname) {
|
||||||
// calculate #options in options list
|
// calculate #options in options list
|
||||||
if (options_single) {
|
if (options_single) {
|
||||||
options_size = 1;
|
options_size = 1;
|
||||||
|
|||||||
@@ -167,23 +167,27 @@ class DeviceValue {
|
|||||||
DV_NUMOP_MUL50 = -50
|
DV_NUMOP_MUL50 = -50
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t device_type; // EMSdevice::DeviceType
|
// Layout chosen for compact packing AND cache locality on 32-bit ESP32.
|
||||||
int8_t tag; // DeviceValueTAG::*
|
// pointers — 5 × 4 bytes, all naturally aligned
|
||||||
void * value_p; // pointer to variable of any type
|
void * value_p; // pointer to variable of any type
|
||||||
uint8_t type; // DeviceValueType::*
|
|
||||||
const char * const ** options; // options as a flash char array
|
|
||||||
const char * const * options_single; // options are not translated
|
|
||||||
int8_t numeric_operator;
|
|
||||||
const char * const short_name; // used in MQTT and API
|
const char * const short_name; // used in MQTT and API
|
||||||
const char * const * fullname; // used in Web and Console, is translated
|
const char * const * fullname; // used in Web and Console, is translated
|
||||||
std::string custom_fullname; // optional, from customization
|
const char * const ** options; // options as a flash char array
|
||||||
|
const char * const * options_single; // options are not translated
|
||||||
|
// single-byte fields packed together — hot fields, share cache line 0 with the pointers above
|
||||||
|
uint8_t device_type; // EMSdevice::DeviceType
|
||||||
|
int8_t tag; // DeviceValueTAG::*
|
||||||
|
uint8_t type; // DeviceValueType::*
|
||||||
|
uint8_t state; // DeviceValueState::*
|
||||||
|
int8_t numeric_operator; // DeviceValueNumOp::*
|
||||||
uint8_t uom; // DeviceValueUOM::*
|
uint8_t uom; // DeviceValueUOM::*
|
||||||
bool has_cmd; // true if there is a Console/MQTT command which matches the short_name
|
bool has_cmd; // true if there is a Console/MQTT command which matches the short_name
|
||||||
|
uint8_t options_size; // number of options in the char array, calculated at class initialization
|
||||||
|
// wider numeric range fields
|
||||||
int16_t min; // min range
|
int16_t min; // min range
|
||||||
uint32_t max; // max range
|
uint32_t max; // max range
|
||||||
uint8_t state; // DeviceValueState::*
|
// largest member last (cold path: only read during customization save/load and web display)
|
||||||
|
std::string custom_fullname; // optional, from customization
|
||||||
uint8_t options_size; // number of options in the char array, calculated at class initialization
|
|
||||||
|
|
||||||
DeviceValue(uint8_t device_type, // EMSdevice::DeviceType
|
DeviceValue(uint8_t device_type, // EMSdevice::DeviceType
|
||||||
int8_t tag, // DeviceValueTAG::*
|
int8_t tag, // DeviceValueTAG::*
|
||||||
|
|||||||
Reference in New Issue
Block a user