1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

Code size optimisation of ESP.getResetReason() (#7029)

* Code size optimisation of ESP.getResetReason()

doing if/else snakes for something that is a switch/case
is wasteful, as it repeatedly evaluates the same if() condition.
Also repeating strcpy_P is adding code bloat.

This simplification reduces size from 111 to 41 bytes.

* add break statement also to default case
This commit is contained in:
Dirk Mueller 2020-01-30 22:07:34 +01:00 committed by GitHub
parent 9e9515b49f
commit a2141803f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -468,23 +468,24 @@ bool EspClass::checkFlashCRC() {
String EspClass::getResetReason(void) { String EspClass::getResetReason(void) {
char buff[32]; const __FlashStringHelper* buff;
if (resetInfo.reason == REASON_DEFAULT_RST) { // normal startup by power on
strcpy_P(buff, PSTR("Power on")); switch(resetInfo.reason) {
} else if (resetInfo.reason == REASON_WDT_RST) { // hardware watch dog reset // normal startup by power on
strcpy_P(buff, PSTR("Hardware Watchdog")); case REASON_DEFAULT_RST: buff = F("Power On"); break;
} else if (resetInfo.reason == REASON_EXCEPTION_RST) { // exception reset, GPIO status wont change // hardware watch dog reset
strcpy_P(buff, PSTR("Exception")); case REASON_WDT_RST: buff = F("Hardware Watchdog"); break;
} else if (resetInfo.reason == REASON_SOFT_WDT_RST) { // software watch dog reset, GPIO status wont change // exception reset, GPIO status wont change
strcpy_P(buff, PSTR("Software Watchdog")); case REASON_EXCEPTION_RST: buff = F("Exception"); break;
} else if (resetInfo.reason == REASON_SOFT_RESTART) { // software restart ,system_restart , GPIO status wont change // software watch dog reset, GPIO status wont change
strcpy_P(buff, PSTR("Software/System restart")); case REASON_SOFT_WDT_RST: buff = F("Software Watchdog"); break;
} else if (resetInfo.reason == REASON_DEEP_SLEEP_AWAKE) { // wake up from deep-sleep // software restart ,system_restart , GPIO status wont change
strcpy_P(buff, PSTR("Deep-Sleep Wake")); case REASON_SOFT_RESTART: buff = F("Software/System restart"); break;
} else if (resetInfo.reason == REASON_EXT_SYS_RST) { // external system reset // wake up from deep-sleep
strcpy_P(buff, PSTR("External System")); case REASON_DEEP_SLEEP_AWAKE: buff = F("Deep-Sleep Wake"); break;
} else { // // external system reset
strcpy_P(buff, PSTR("Unknown")); case REASON_EXT_SYS_RST: buff = F("External System"); break;
default: buff = F("Unknown"); break;
} }
return String(buff); return String(buff);
} }