Skip to content

Commit 953dfd9

Browse files
authored
Avoid float-double-conversion (#7559)
Converting floats to doubles is very expensive on esp8266, so prefer calculations or comparisons as float. This saves 10% (20 bytes) of the String::parseFloat() code size and probably quite a bit of runtime overhead.
1 parent 5987390 commit 953dfd9

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

cores/esp8266/Stream.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ float Stream::parseFloat(char skipChar) {
173173
boolean isFraction = false;
174174
long value = 0;
175175
int c;
176-
float fraction = 1.0;
176+
float fraction = 1.0f;
177177

178178
c = peekNextDigit();
179179
// ignore non numeric leading characters
@@ -190,7 +190,7 @@ float Stream::parseFloat(char skipChar) {
190190
else if(c >= '0' && c <= '9') { // is c a digit?
191191
value = value * 10 + c - '0';
192192
if(isFraction)
193-
fraction *= 0.1;
193+
fraction *= 0.1f;
194194
}
195195
read(); // consume the character we got with peek
196196
c = timedPeek();

libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,10 @@ WiFiPhyMode_t ESP8266WiFiGenericClass::getPhyMode() {
369369
*/
370370
void ESP8266WiFiGenericClass::setOutputPower(float dBm) {
371371

372-
if(dBm > 20.5) {
373-
dBm = 20.5;
374-
} else if(dBm < 0) {
375-
dBm = 0;
372+
if(dBm > 20.5f) {
373+
dBm = 20.5f;
374+
} else if(dBm < 0.0f) {
375+
dBm = 0.0f;
376376
}
377377

378378
uint8_t val = (dBm*4.0f);

0 commit comments

Comments
 (0)