Skip to content
Permalink
Browse files

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.
  • Loading branch information...
dirkmueller authored and me-no-dev committed Oct 2, 2019
1 parent d0b064a commit 6f70e27011d1f1aae222b735cdf6dc1380b062a9
Showing with 6 additions and 6 deletions.
  1. +4 −4 cores/esp32/base64.cpp
  2. +2 −2 cores/esp32/base64.h
@@ -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());
}
@@ -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:
};

0 comments on commit 6f70e27

Please sign in to comment.
You can’t perform that action at this time.