mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-21 10:26:06 +03:00
Base64::encode : const correctness / String by reference passing (#6581)
This is another instance in the core library 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.
This commit is contained in:
parent
3890e1af1e
commit
bab2880f01
@ -31,11 +31,11 @@ extern "C" {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* convert input data to base64
|
* convert input data to base64
|
||||||
* @param data uint8_t *
|
* @param data const uint8_t *
|
||||||
* @param length size_t
|
* @param length size_t
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
String base64::encode(uint8_t * data, size_t length, bool doNewLines) {
|
String base64::encode(const uint8_t * data, size_t length, bool doNewLines) {
|
||||||
// base64 needs more size then the source data, use cencode.h macros
|
// base64 needs more size then the source data, use cencode.h macros
|
||||||
size_t size = ((doNewLines ? base64_encode_expected_len(length)
|
size_t size = ((doNewLines ? base64_encode_expected_len(length)
|
||||||
: base64_encode_expected_len_nonewlines(length)) + 1);
|
: base64_encode_expected_len_nonewlines(length)) + 1);
|
||||||
@ -62,10 +62,10 @@ String base64::encode(uint8_t * data, size_t length, bool doNewLines) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* convert input data to base64
|
* convert input data to base64
|
||||||
* @param text String
|
* @param text const String&
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
String base64::encode(String text, bool doNewLines) {
|
String base64::encode(const String& text, bool doNewLines) {
|
||||||
return base64::encode((uint8_t *) text.c_str(), text.length(), doNewLines);
|
return base64::encode((const uint8_t *) text.c_str(), text.length(), doNewLines);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@ class base64 {
|
|||||||
// NOTE: The default behaviour of backend (lib64)
|
// NOTE: The default behaviour of backend (lib64)
|
||||||
// is to add a newline every 72 (encoded) characters output.
|
// is to add a newline every 72 (encoded) characters output.
|
||||||
// This may 'break' longer uris and json variables
|
// This may 'break' longer uris and json variables
|
||||||
static String encode(uint8_t * data, size_t length, bool doNewLines = true);
|
static String encode(const uint8_t * data, size_t length, bool doNewLines = true);
|
||||||
static String encode(String text, bool doNewLines = true);
|
static String encode(const String& text, bool doNewLines = true);
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user