- Optimize std::string in function params by passing in a const reference
This commit is contained in:
ZanzyTHEbar 2022-08-29 15:02:40 +01:00
parent 41fe047f7a
commit 19733adcf8
10 changed files with 24 additions and 24 deletions

View File

@ -69,7 +69,7 @@ void ProjectConfig::load()
log_d("Project config found - Config length: %d", configLen); log_d("Project config found - Config length: %d", configLen);
char buff[configLen]; char buff[configLen];
getBytes("config", buff, configLen); getBytes("projectConf", buff, configLen);
for (int i = 0; i < configLen; i++) for (int i = 0; i < configLen; i++)
Serial.printf("%02X ", buff[i]); Serial.printf("%02X ", buff[i]);
@ -83,7 +83,7 @@ void ProjectConfig::save()
log_d("Saving project config"); log_d("Saving project config");
TrackerConfig_t *tracker_config = (TrackerConfig_t *)&this->config; TrackerConfig_t *tracker_config = (TrackerConfig_t *)&this->config;
putBytes("config", tracker_config, 3 * sizeof(TrackerConfig_t)); putBytes("projectConf", tracker_config, 3 * sizeof(TrackerConfig_t));
log_i("Project config saved and system is rebooting"); log_i("Project config saved and system is rebooting");
delay(20000); delay(20000);

View File

@ -32,7 +32,7 @@ char *Helpers::itoa(int value, char *result, int base)
return result; return result;
} }
void split(std::string str, std::string splitBy, std::vector<std::string> &tokens) void split(const std::string &str, const std::string &splitBy, std::vector<std::string> &tokens)
{ {
/* Store the original string in the array, so we can loop the rest /* Store the original string in the array, so we can loop the rest
* of the algorithm. */ * of the algorithm. */

View File

@ -12,8 +12,8 @@ class WiFiHandler
{ {
public: public:
WiFiHandler(ProjectConfig *configManager, StateManager<WiFiState_e> *stateManager, WiFiHandler(ProjectConfig *configManager, StateManager<WiFiState_e> *stateManager,
std::string ssid, const std::string &ssid,
std::string password, const std::string &password,
uint8_t channel); uint8_t channel);
virtual ~WiFiHandler(); virtual ~WiFiHandler();
void setupWifi(); void setupWifi();

View File

@ -3,8 +3,8 @@
WiFiHandler::WiFiHandler(ProjectConfig *configManager, WiFiHandler::WiFiHandler(ProjectConfig *configManager,
StateManager<WiFiState_e> *stateManager, StateManager<WiFiState_e> *stateManager,
std::string ssid, const std::string &ssid,
std::string password, const std::string &password,
uint8_t channel) : configManager(configManager), uint8_t channel) : configManager(configManager),
stateManager(stateManager), stateManager(stateManager),
ssid(ssid), ssid(ssid),

View File

@ -4,7 +4,7 @@ BaseAPI::BaseAPI(int CONTROL_PORT,
WiFiHandler *network, WiFiHandler *network,
CameraHandler *camera, CameraHandler *camera,
StateManager<WiFiState_e> *stateManager, StateManager<WiFiState_e> *stateManager,
std::string api_url) : API_Utilities(CONTROL_PORT, const std::string &api_url) : API_Utilities(CONTROL_PORT,
network, network,
camera, camera,
stateManager, stateManager,

View File

@ -74,7 +74,7 @@ public:
WiFiHandler *network, WiFiHandler *network,
CameraHandler *camera, CameraHandler *camera,
StateManager<WiFiState_e> *stateManager, StateManager<WiFiState_e> *stateManager,
std::string api_url); const std::string &api_url);
virtual ~BaseAPI(); virtual ~BaseAPI();
virtual void begin(); virtual void begin();

View File

@ -22,7 +22,7 @@ API_Utilities::API_Utilities(int CONTROL_PORT,
WiFiHandler *network, WiFiHandler *network,
CameraHandler *camera, CameraHandler *camera,
StateManager<WiFiState_e> *stateManager, StateManager<WiFiState_e> *stateManager,
std::string api_url) : server(new AsyncWebServer(CONTROL_PORT)), const std::string &api_url) : server(new AsyncWebServer(CONTROL_PORT)),
stateManager(stateManager), stateManager(stateManager),
network(network), network(network),
camera(camera), camera(camera),

View File

@ -33,7 +33,7 @@ public:
WiFiHandler *network, WiFiHandler *network,
CameraHandler *camera, CameraHandler *camera,
StateManager<WiFiState_e> *stateManager, StateManager<WiFiState_e> *stateManager,
std::string api_url); const std::string &api_url);
virtual ~API_Utilities(); virtual ~API_Utilities();
static void printASCII(); static void printASCII();

View File

@ -8,11 +8,11 @@ APIServer::APIServer(int CONTROL_PORT,
WiFiHandler *network, WiFiHandler *network,
CameraHandler *camera, CameraHandler *camera,
StateManager<WiFiState_e> *stateManager, StateManager<WiFiState_e> *stateManager,
std::string api_url) : BaseAPI(CONTROL_PORT, const std::string &api_url) : BaseAPI(CONTROL_PORT,
network, network,
camera, camera,
stateManager, stateManager,
api_url) {} api_url) {}
APIServer::~APIServer() {} APIServer::~APIServer() {}
@ -47,11 +47,11 @@ void APIServer::setupServer()
addRouteMap("builtin", routes, indexes); // add new route map to the route_map addRouteMap("builtin", routes, indexes); // add new route map to the route_map
} }
void APIServer::findParam(AsyncWebServerRequest *request, const char *param, String &value) void APIServer::findParam(AsyncWebServerRequest *request, const char *param, std::string &value)
{ {
if (request->hasParam(param)) if (request->hasParam(param))
{ {
value = request->getParam(param)->value(); value = request->getParam(param)->value().c_str();
} }
} }
@ -65,7 +65,7 @@ void APIServer::findParam(AsyncWebServerRequest *request, const char *param, Str
* @return void * @return void
* *
*/ */
void APIServer::addRouteMap(std::string index, route_t route, std::vector<std::string> &indexes) void APIServer::addRouteMap(const std::string &index, route_t route, std::vector<std::string> &indexes)
{ {
route_map.emplace(index, route); route_map.emplace(index, route);

View File

@ -11,13 +11,13 @@ public:
WiFiHandler *network, WiFiHandler *network,
CameraHandler *camera, CameraHandler *camera,
StateManager<WiFiState_e> *stateManager, StateManager<WiFiState_e> *stateManager,
std::string api_url); const std::string &api_url);
virtual ~APIServer(); virtual ~APIServer();
void begin(); void begin();
void setupServer(); void setupServer();
void findParam(AsyncWebServerRequest *request, const char *param, String &value); void findParam(AsyncWebServerRequest *request, const char *param, std::string &value);
void addRouteMap(std::string index, route_t route, std::vector<std::string> &indexes); void addRouteMap(const std::string &index, route_t route, std::vector<std::string> &indexes);
void handleRequest(AsyncWebServerRequest *request); void handleRequest(AsyncWebServerRequest *request);
public: public: