- 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);
char buff[configLen];
getBytes("config", buff, configLen);
getBytes("projectConf", buff, configLen);
for (int i = 0; i < configLen; i++)
Serial.printf("%02X ", buff[i]);
@ -83,7 +83,7 @@ void ProjectConfig::save()
log_d("Saving project 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");
delay(20000);

View File

@ -32,7 +32,7 @@ char *Helpers::itoa(int value, char *result, int base)
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
* of the algorithm. */

View File

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

View File

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

View File

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

View File

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

View File

@ -22,7 +22,7 @@ API_Utilities::API_Utilities(int CONTROL_PORT,
WiFiHandler *network,
CameraHandler *camera,
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),
network(network),
camera(camera),

View File

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

View File

@ -8,11 +8,11 @@ APIServer::APIServer(int CONTROL_PORT,
WiFiHandler *network,
CameraHandler *camera,
StateManager<WiFiState_e> *stateManager,
std::string api_url) : BaseAPI(CONTROL_PORT,
network,
camera,
stateManager,
api_url) {}
const std::string &api_url) : BaseAPI(CONTROL_PORT,
network,
camera,
stateManager,
api_url) {}
APIServer::~APIServer() {}
@ -47,11 +47,11 @@ void APIServer::setupServer()
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))
{
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
*
*/
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);

View File

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