Skip to content

fix(core): StreamString performance improvements with large buffers (positional index instead of memory move) #11232

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
15 changes: 3 additions & 12 deletions cores/esp32/StreamString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,15 @@ size_t StreamString::write(uint8_t data) {
}

int StreamString::available() {
return length();
return length() - _start;
}

int StreamString::read() {
if (length()) {
char c = charAt(0);
remove(0, 1);
return c;
}
return -1;
return available() ? charAt(_start++) : -1;
}

int StreamString::peek() {
if (length()) {
char c = charAt(0);
return c;
}
return -1;
return available() ? charAt(_start) : -1;
}

void StreamString::flush() {}
4 changes: 4 additions & 0 deletions cores/esp32/StreamString.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class StreamString : public Stream, public String {
int read() override;
int peek() override;
void flush() override;

private:
// read position
unsigned int _start = 0;
};

#endif /* STREAMSTRING_H_ */
Loading