Skip to content

Commit b1b6615

Browse files
committed
fix(core): StreamString performance improvements
1 parent b333bf2 commit b1b6615

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

Diff for: cores/esp32/StreamString.cpp

+3-12
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,15 @@ size_t StreamString::write(uint8_t data) {
4141
}
4242

4343
int StreamString::available() {
44-
return length();
44+
return length() - _start;
4545
}
4646

4747
int StreamString::read() {
48-
if (length()) {
49-
char c = charAt(0);
50-
remove(0, 1);
51-
return c;
52-
}
53-
return -1;
48+
return available() ? charAt(_start++) : -1;
5449
}
5550

5651
int StreamString::peek() {
57-
if (length()) {
58-
char c = charAt(0);
59-
return c;
60-
}
61-
return -1;
52+
return available() ? charAt(_start) : -1;
6253
}
6354

6455
void StreamString::flush() {}

Diff for: cores/esp32/StreamString.h

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ class StreamString : public Stream, public String {
3333
int read() override;
3434
int peek() override;
3535
void flush() override;
36+
37+
private:
38+
// read position
39+
unsigned int _start = 0;
3640
};
3741

3842
#endif /* STREAMSTRING_H_ */

0 commit comments

Comments
 (0)