1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-27 18:02:17 +03:00

Further const correctness / String by reference passing cleanups (#6571)

There are actually several instances where we pass in read-only
parameters as pass-by-value, where in the case of String() that
is inefficient as it involves copy-constructor/temp string creations.

We can avoid that, similarly to single character string concatenations
done via string literals instead of char literals.
This commit is contained in:
Dirk Mueller
2019-10-31 16:02:40 +01:00
committed by david gauchard
parent ba971fe7e9
commit 8bc5a10d6d
11 changed files with 78 additions and 75 deletions

View File

@ -277,7 +277,7 @@ bool MDNSResponder::addServiceTxt(char *name, char *proto, char *key, char *valu
return false; //max txt record size
}
MDNSTxt *newtxt = new MDNSTxt;
newtxt->_txt = String(key) + "=" + String(value);
newtxt->_txt = String(key) + '=' + String(value);
newtxt->_next = 0;
if (servicePtr->_txts == 0) //no services have been added
{

View File

@ -280,7 +280,7 @@ bool MDNSResponder::setHostname(const char* p_pcHostname)
/*
MDNSResponder::setHostname (LEGACY)
*/
bool MDNSResponder::setHostname(String p_strHostname)
bool MDNSResponder::setHostname(const String& p_strHostname)
{
return setHostname(p_strHostname.c_str());
@ -369,8 +369,8 @@ bool MDNSResponder::removeService(const char* p_pcName,
/*
MDNSResponder::addService (LEGACY)
*/
bool MDNSResponder::addService(String p_strService,
String p_strProtocol,
bool MDNSResponder::addService(const String& p_strService,
const String& p_strProtocol,
uint16_t p_u16Port)
{
@ -595,10 +595,10 @@ bool MDNSResponder::addServiceTxt(const char* p_pcService,
/*
MDNSResponder::addServiceTxt (LEGACY)
*/
bool MDNSResponder::addServiceTxt(String p_strService,
String p_strProtocol,
String p_strKey,
String p_strValue)
bool MDNSResponder::addServiceTxt(const String& p_strService,
const String& p_strProtocol,
const String& p_strKey,
const String& p_strValue)
{
return (0 != _addServiceTxt(_findService(m_pcHostname, p_strService.c_str(), p_strProtocol.c_str()), p_strKey.c_str(), p_strValue.c_str(), false));
@ -826,8 +826,8 @@ bool MDNSResponder::removeQuery(void)
/*
MDNSResponder::queryService (LEGACY)
*/
uint32_t MDNSResponder::queryService(String p_strService,
String p_strProtocol)
uint32_t MDNSResponder::queryService(const String& p_strService,
const String& p_strProtocol)
{
return queryService(p_strService.c_str(), p_strProtocol.c_str());

View File

@ -192,7 +192,7 @@ public:
// Change hostname (probing is restarted)
bool setHostname(const char* p_pcHostname);
// for compatibility...
bool setHostname(String p_strHostname);
bool setHostname(const String& p_strHostname);
/**
hMDNSService (opaque handle to access the service)
@ -213,8 +213,8 @@ public:
const char* p_pcServiceName,
const char* p_pcProtocol);
// for compatibility...
bool addService(String p_strServiceName,
String p_strProtocol,
bool addService(const String& p_strServiceName,
const String& p_strProtocol,
uint16_t p_u16Port);
@ -276,10 +276,10 @@ public:
const char* p_pcProtocol,
const char* p_pcKey,
const char* p_pcValue);
bool addServiceTxt(String p_strService,
String p_strProtocol,
String p_strKey,
String p_strValue);
bool addServiceTxt(const String& p_strService,
const String& p_strProtocol,
const String& p_strKey,
const String& p_strValue);
/**
MDNSDynamicServiceTxtCallbackFn
@ -331,8 +331,8 @@ public:
const uint16_t p_u16Timeout = MDNS_QUERYSERVICES_WAIT_TIME);
bool removeQuery(void);
// for compatibility...
uint32_t queryService(String p_strService,
String p_strProtocol);
uint32_t queryService(const String& p_strService,
const String& p_strProtocol);
const char* answerHostname(const uint32_t p_u32AnswerIndex);
IPAddress answerIP(const uint32_t p_u32AnswerIndex);