Skip to content
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

Use 128B chunks instead of 1B writes in Print::print(FlashStringHelper) #6893

Merged
merged 1 commit into from
Dec 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions cores/esp8266/Print.cpp
Original file line number Diff line number Diff line change
@@ -104,11 +104,19 @@ size_t Print::printf_P(PGM_P format, ...) {
size_t Print::print(const __FlashStringHelper *ifsh) {
PGM_P p = reinterpret_cast<PGM_P>(ifsh);

char buff[128] __attribute__ ((aligned(4)));
auto len = strlen_P(p);
size_t n = 0;
while (1) {
uint8_t c = pgm_read_byte(p++);
if (c == 0) break;
n += write(c);
while (n < len) {
int to_write = std::min(sizeof(buff), len - n);
memcpy_P(buff, p, to_write);
auto written = write(buff, to_write);
n += written;
p += written;
if (!written) {
// Some error, write() should write at least 1 byte before returning
break;
}
}
return n;
}