Skip to content

Commit 6f70e27

Browse files
dirkmuellerme-no-dev
authored andcommitted
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.
1 parent d0b064a commit 6f70e27

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

cores/esp32/base64.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ extern "C" {
3131

3232
/**
3333
* convert input data to base64
34-
* @param data uint8_t *
34+
* @param data const uint8_t *
3535
* @param length size_t
3636
* @return String
3737
*/
38-
String base64::encode(uint8_t * data, size_t length)
38+
String base64::encode(const uint8_t * data, size_t length)
3939
{
4040
size_t size = base64_encode_expected_len(length) + 1;
4141
char * buffer = (char *) malloc(size);
@@ -54,10 +54,10 @@ String base64::encode(uint8_t * data, size_t length)
5454

5555
/**
5656
* convert input data to base64
57-
* @param text String
57+
* @param text const String&
5858
* @return String
5959
*/
60-
String base64::encode(String text)
60+
String base64::encode(const String& text)
6161
{
6262
return base64::encode((uint8_t *) text.c_str(), text.length());
6363
}

cores/esp32/base64.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
class base64
55
{
66
public:
7-
static String encode(uint8_t * data, size_t length);
8-
static String encode(String text);
7+
static String encode(const uint8_t * data, size_t length);
8+
static String encode(const String& text);
99
private:
1010
};
1111

0 commit comments

Comments
 (0)