minor std::string optimizations

This commit is contained in:
proddy
2024-09-15 12:33:27 +02:00
parent 9a20bf350a
commit e54d9a6c32
6 changed files with 10 additions and 10 deletions

View File

@@ -578,7 +578,7 @@ void EMSdevice::add_device_value(int8_t tag, // to b
snprintf(entity, sizeof(entity), "%s/%s", tag_to_mqtt(tag), short_name); snprintf(entity, sizeof(entity), "%s/%s", tag_to_mqtt(tag), short_name);
} }
for (std::string entity_id : entityCustomization.entity_ids) { for (const std::string & entity_id : entityCustomization.entity_ids) {
// if there is an appended custom name, strip it to get the true entity name // if there is an appended custom name, strip it to get the true entity name
// and extract the new custom name // and extract the new custom name
auto custom_name_pos = entity_id.find('|'); auto custom_name_pos = entity_id.find('|');
@@ -1112,7 +1112,7 @@ void EMSdevice::generate_values_web_customization(JsonArray output) {
EMSESP::webCustomizationService.read([&](WebCustomization & settings) { EMSESP::webCustomizationService.read([&](WebCustomization & settings) {
for (EntityCustomization entityCustomization : settings.entityCustomizations) { for (EntityCustomization entityCustomization : settings.entityCustomizations) {
if (entityCustomization.device_id == device_id()) { if (entityCustomization.device_id == device_id()) {
for (std::string entity_id : entityCustomization.entity_ids) { for (const std::string & entity_id : entityCustomization.entity_ids) {
uint8_t mask = Helpers::hextoint(entity_id.substr(0, 2).c_str()); uint8_t mask = Helpers::hextoint(entity_id.substr(0, 2).c_str());
if (mask & 0x80) { if (mask & 0x80) {
JsonObject obj = output.add<JsonObject>(); JsonObject obj = output.add<JsonObject>();

View File

@@ -369,7 +369,7 @@ std::string DeviceValue::get_fullname() const {
return customname; return customname;
} }
std::string DeviceValue::get_name(std::string & entity) { std::string DeviceValue::get_name(const std::string & entity) {
auto pos = entity.find('|'); auto pos = entity.find('|');
if (pos != std::string::npos) { if (pos != std::string::npos) {
return entity.substr(2, pos - 2); return entity.substr(2, pos - 2);

View File

@@ -188,7 +188,7 @@ class DeviceValue {
bool get_custom_max(uint32_t & val); bool get_custom_max(uint32_t & val);
std::string get_custom_fullname() const; std::string get_custom_fullname() const;
std::string get_fullname() const; std::string get_fullname() const;
static std::string get_name(std::string & entity); static std::string get_name(const std::string & entity);
// dv state flags // dv state flags
void add_state(uint8_t s) { void add_state(uint8_t s) {

View File

@@ -201,7 +201,7 @@ class System {
return hostname_; return hostname_;
} }
void hostname(std::string hostname) { void hostname(const std::string hostname) {
hostname_ = hostname; hostname_ = hostname;
} }

View File

@@ -75,7 +75,7 @@ void WebCustomization::read(WebCustomization & customizations, JsonObject root)
// entries are in the form <XX><shortname>[optional customname] e.g "08heatingactive|heating is on" // entries are in the form <XX><shortname>[optional customname] e.g "08heatingactive|heating is on"
JsonArray masked_entityJson = entityJson["entity_ids"].to<JsonArray>(); JsonArray masked_entityJson = entityJson["entity_ids"].to<JsonArray>();
for (std::string entity_id : entityCustomization.entity_ids) { for (const std::string & entity_id : entityCustomization.entity_ids) {
masked_entityJson.add(entity_id); masked_entityJson.add(entity_id);
} }
} }
@@ -277,7 +277,7 @@ void WebCustomizationService::customization_entities(AsyncWebServerRequest * req
read([&](WebCustomization & settings) { read([&](WebCustomization & settings) {
for (EntityCustomization entityCustomization : settings.entityCustomizations) { for (EntityCustomization entityCustomization : settings.entityCustomizations) {
if (entityCustomization.device_id == device_id) { if (entityCustomization.device_id == device_id) {
for (std::string entity_id : entityCustomization.entity_ids) { for (const std::string & entity_id : entityCustomization.entity_ids) {
uint8_t mask = Helpers::hextoint(entity_id.substr(0, 2).c_str()); uint8_t mask = Helpers::hextoint(entity_id.substr(0, 2).c_str());
std::string name = DeviceValue::get_name(entity_id); std::string name = DeviceValue::get_name(entity_id);
if (mask & 0x80) { if (mask & 0x80) {

View File

@@ -152,7 +152,7 @@ void WebStatusService::checkUpgrade(AsyncWebServerRequest * request, JsonVariant
JsonObject root = response->getRoot(); JsonObject root = response->getRoot();
version::Semver200_version settings_version(EMSESP_APP_VERSION); version::Semver200_version settings_version(EMSESP_APP_VERSION);
std::string latest_version = json["version"] | EMSESP_APP_VERSION; const std::string latest_version = json["version"] | EMSESP_APP_VERSION;
version::Semver200_version this_version(latest_version); version::Semver200_version this_version(latest_version);
#ifdef EMSESP_DEBUG #ifdef EMSESP_DEBUG
@@ -171,6 +171,7 @@ void WebStatusService::exportData(AsyncWebServerRequest * request) {
JsonObject root = response->getRoot(); JsonObject root = response->getRoot();
String type = request->getParam("type")->value(); String type = request->getParam("type")->value();
root["type"] = type;
if (type == "settings") { if (type == "settings") {
JsonObject node = root["System"].to<JsonObject>(); JsonObject node = root["System"].to<JsonObject>();
@@ -192,7 +193,6 @@ void WebStatusService::exportData(AsyncWebServerRequest * request) {
return; return;
} }
root["type"] = type;
response->setLength(); response->setLength();
request->send(response); request->send(response);
} }