mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-17 12:02:15 +03:00
Use 128B chunks instead of 1B writes in Print::print(FlashStringHelper) (#6893)
Fixes #6524 Should help with speed of output when printing large flash strings to things like a file or a TCP connection. Use a 128 byte chunk in a temp buffer to send data using write(), reducing the # of write calls by ~128x.
This commit is contained in:
committed by
Develo
parent
7605dc1643
commit
759ba27b62
@ -104,11 +104,19 @@ size_t Print::printf_P(PGM_P format, ...) {
|
|||||||
size_t Print::print(const __FlashStringHelper *ifsh) {
|
size_t Print::print(const __FlashStringHelper *ifsh) {
|
||||||
PGM_P p = reinterpret_cast<PGM_P>(ifsh);
|
PGM_P p = reinterpret_cast<PGM_P>(ifsh);
|
||||||
|
|
||||||
|
char buff[128] __attribute__ ((aligned(4)));
|
||||||
|
auto len = strlen_P(p);
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
while (1) {
|
while (n < len) {
|
||||||
uint8_t c = pgm_read_byte(p++);
|
int to_write = std::min(sizeof(buff), len - n);
|
||||||
if (c == 0) break;
|
memcpy_P(buff, p, to_write);
|
||||||
n += write(c);
|
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;
|
return n;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user