-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inefficient Print:write(data,len) shows message if used (only in debug mode) #4537
Conversation
cores/esp8266/Print.cpp
Outdated
size_t n = 0; | ||
while (size--) { | ||
size_t ret = write(*buffer++); | ||
if (ret == 0) { | ||
if (ret <= 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ret is declared of type size_t, which should be unsigned, which means it can't be negative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes very true. Blinded with ::read, arduino's api should all get a major reshape for coherency.
cores/esp8266/uart.c
Outdated
@@ -196,23 +196,30 @@ void uart_stop_isr(uart_t* uart) | |||
} | |||
|
|||
|
|||
void uart_write_char(uart_t* uart, char c) | |||
void uart_do_write_char(uart_t* uart, char c) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe declare this one as inline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I actually don't understand why inline does save flash space here.
This means one while loop and 2 calls with 2 parameters each take 16 more flash bytes than two while loops.
I was thinking gcc -Os would optimize this itself [...] Well, it would have if I had not forgotten static
. Then I'd prefer the static way.
…g mode) +fix HardwareSerial that used it
…lls to .h to give gcc a chance to optimize them
Last "remove duplicate code" commit spares ~100 bytes of flash. edit: So finally
edit 2: |
…ug mode) (esp8266#4537) * inefficient Print::write(data,len) shows message if used (only in debug mode) * make HardwareSerial's write(data,len) efficient * HardwareSerial: remove duplicate tests, move trivial code from .cpp to .h (cherry picked from commit f8f205d)
+fix HardwareSerial that used it