Skip to content

Commit e83dd4d

Browse files
Use lightweight tests when we only care if the buffer is empty or full.
1 parent e147314 commit e83dd4d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

cores/esp8266/cbuf.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,22 @@ class cbuf {
4545
return _begin - _end - 1;
4646
}
4747

48-
bool empty() const {
48+
inline bool empty() const {
4949
return _begin == _end;
5050
}
5151

52+
inline bool full() const {
53+
return wrap_if_bufend(_end + 1) == _begin;
54+
}
55+
5256
int peek() {
53-
if(_end == _begin) return -1;
57+
if(empty()) return -1;
5458

5559
return static_cast<int>(*_begin);
5660
}
5761

5862
int read() {
59-
if(getSize() == 0) return -1;
63+
if(empty()) return -1;
6064

6165
char result = *_begin;
6266
_begin = wrap_if_bufend(_begin + 1);
@@ -80,7 +84,7 @@ class cbuf {
8084
}
8185

8286
size_t write(char c) {
83-
if(room() == 0) return 0;
87+
if(full()) return 0;
8488

8589
*_end = c;
8690
_end = wrap_if_bufend(_end + 1);
@@ -109,7 +113,7 @@ class cbuf {
109113
}
110114

111115
private:
112-
inline char* wrap_if_bufend(char* ptr) {
116+
inline char* wrap_if_bufend(char* ptr) const {
113117
return (ptr == _bufend) ? _buf : ptr;
114118
}
115119

0 commit comments

Comments
 (0)