Skip to content

Commit 6c2ab25

Browse files
dirkmuellerearlephilhower
authored andcommitted
Code size optimisations for ESP.getFullVersion() (#6936)
This saves about ~ 60 bytes of flash usage (50% reduction of the total function size)
1 parent 99aeead commit 6c2ab25

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

cores/esp8266/Esp-version.cpp

+28-16
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,41 @@
2828
#define STRHELPER(x) #x
2929
#define STR(x) STRHELPER(x) // stringifier
3030

31-
static const char arduino_esp8266_git_ver [] PROGMEM = STR(ARDUINO_ESP8266_GIT_DESC);
31+
static const char arduino_esp8266_git_ver [] PROGMEM = "/Core:" STR(ARDUINO_ESP8266_GIT_DESC) "=";
32+
#if LWIP_VERSION_MAJOR > 1
33+
#if LWIP_IPV6
34+
static const char lwip_version [] PROGMEM = "/lwIP:IPv6+" LWIP_HASH_STR;
35+
#else
36+
static const char lwip_version [] PROGMEM = "/lwIP:" LWIP_HASH_STR;
37+
#endif
38+
#endif
3239
static const char bearssl_version [] PROGMEM = "/BearSSL:" STR(BEARSSL_GIT);
3340

34-
String EspClass::getFullVersion()
35-
{
36-
return String(F("SDK:")) + system_get_sdk_version()
37-
+ F("/Core:") + FPSTR(arduino_esp8266_git_ver)
38-
+ F("=") + String(esp8266::coreVersionNumeric())
41+
String EspClass::getFullVersion() {
42+
String s(F("SDK:"));
43+
s.reserve(127);
44+
45+
s += system_get_sdk_version();
46+
s += FPSTR(arduino_esp8266_git_ver);
47+
s += String(esp8266::coreVersionNumeric());
3948
#if LWIP_VERSION_MAJOR == 1
40-
+ F("/lwIP:") + String(LWIP_VERSION_MAJOR) + "." + String(LWIP_VERSION_MINOR) + "." + String(LWIP_VERSION_REVISION)
49+
s += F("/lwIP:");
50+
s += LWIP_VERSION_MAJOR;
51+
s += '.';
52+
s += LWIP_VERSION_MINOR;
53+
s += '.';
54+
s += LWIP_VERSION_REVISION;
4155
#if LWIP_VERSION_IS_DEVELOPMENT
42-
+ F("-dev")
56+
s += F("-dev");
4357
#endif
4458
#if LWIP_VERSION_IS_RC
45-
+ F("rc") + String(LWIP_VERSION_RC)
59+
s += F("rc");
60+
s += String(LWIP_VERSION_RC);
4661
#endif
4762
#else // LWIP_VERSION_MAJOR != 1
48-
+ F("/lwIP:")
49-
#if LWIP_IPV6
50-
+ F("IPv6+")
51-
#endif // LWIP_IPV6
52-
+ F(LWIP_HASH_STR)
63+
s += FPSTR(lwip_version);
5364
#endif // LWIP_VERSION_MAJOR != 1
54-
+ FPSTR(bearssl_version)
55-
;
65+
s += FPSTR(bearssl_version);
66+
67+
return s;
5668
}

0 commit comments

Comments
 (0)