mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 23:21:54 +00:00 
			
		
		
		
	[core] Store BASE64 chars in flash memory array
This commit is contained in:
		| @@ -373,10 +373,11 @@ int8_t step_to_accuracy_decimals(float step) { | |||||||
|   return str.length() - dot_pos - 1; |   return str.length() - dot_pos - 1; | ||||||
| } | } | ||||||
|  |  | ||||||
| // Use C-style string constant to store in ROM instead of RAM (saves 24 bytes) | // Store BASE64 characters as array - automatically placed in flash/ROM on embedded platforms | ||||||
| static constexpr const char *BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | static const char BASE64_CHARS[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', | ||||||
|                                             "abcdefghijklmnopqrstuvwxyz" |                                     'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', | ||||||
|                                             "0123456789+/"; |                                     'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', | ||||||
|  |                                     'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'}; | ||||||
|  |  | ||||||
| // Helper function to find the index of a base64 character in the lookup table. | // Helper function to find the index of a base64 character in the lookup table. | ||||||
| // Returns the character's position (0-63) if found, or 0 if not found. | // Returns the character's position (0-63) if found, or 0 if not found. | ||||||
| @@ -386,8 +387,8 @@ static constexpr const char *BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |||||||
| // stops processing at the first invalid character due to the is_base64() check in its | // stops processing at the first invalid character due to the is_base64() check in its | ||||||
| // while loop condition, making this edge case harmless in practice. | // while loop condition, making this edge case harmless in practice. | ||||||
| static inline uint8_t base64_find_char(char c) { | static inline uint8_t base64_find_char(char c) { | ||||||
|   const char *pos = strchr(BASE64_CHARS, c); |   const void *ptr = memchr(BASE64_CHARS, c, sizeof(BASE64_CHARS)); | ||||||
|   return pos ? (pos - BASE64_CHARS) : 0; |   return ptr ? (static_cast<const char *>(ptr) - BASE64_CHARS) : 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| static inline bool is_base64(char c) { return (isalnum(c) || (c == '+') || (c == '/')); } | static inline bool is_base64(char c) { return (isalnum(c) || (c == '+') || (c == '/')); } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user