Base64::encode : const correctness / String by reference passing (#3314)

Avoid passing String by-value, which is slightly less efficient
as it involves a full copy-constructor/tempstring creation.
This commit is contained in:
Dirk Mueller 2019-10-02 13:29:24 +02:00 committed by Me No Dev
parent d0b064a1ee
commit 6f70e27011
2 changed files with 6 additions and 6 deletions

View File

@ -31,11 +31,11 @@ extern "C" {
/**
* convert input data to base64
* @param data uint8_t *
* @param data const uint8_t *
* @param length size_t
* @return String
*/
String base64::encode(uint8_t * data, size_t length)
String base64::encode(const uint8_t * data, size_t length)
{
size_t size = base64_encode_expected_len(length) + 1;
char * buffer = (char *) malloc(size);
@ -54,10 +54,10 @@ String base64::encode(uint8_t * data, size_t length)
/**
* convert input data to base64
* @param text String
* @param text const String&
* @return String
*/
String base64::encode(String text)
String base64::encode(const String& text)
{
return base64::encode((uint8_t *) text.c_str(), text.length());
}

View File

@ -4,8 +4,8 @@
class base64
{
public:
static String encode(uint8_t * data, size_t length);
static String encode(String text);
static String encode(const uint8_t * data, size_t length);
static String encode(const String& text);
private:
};