Skip to content

Commit 8013ef4

Browse files
jeplerdpgeorge
authored andcommitted
extmod/modwebsocket: Save a few bytes of text by using bit checks.
.. at least on x86_64 (unix standard build). Size was unchanged on RPI_PICO_W. Signed-off-by: Jeff Epler <[email protected]>
1 parent b94162b commit 8013ef4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

extmod/modwebsocket.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ static mp_uint_t websocket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int
143143
}
144144

145145
case FRAME_OPT: {
146-
if ((self->buf_pos & 3) == 2) {
147-
// First two bytes are message length
146+
if (self->buf_pos & 2) { // to_recv was 2 or 6
147+
assert(self->buf_pos == 2 || self->buf_pos == 6);
148148
// First two bytes are message length. Technically the size must be at least 126 per RFC6455
149149
// but MicroPython skips checking that.
150150
self->msg_sz = (self->buf[0] << 8) | self->buf[1];
151151
}
152-
if (self->buf_pos >= 4) {
152+
if (self->buf_pos & 4) {
153153
// Last 4 bytes is mask
154154
memcpy(self->mask, self->buf + self->buf_pos - 4, 4);
155155
}

0 commit comments

Comments
 (0)