Micro-optimization
This commit is contained in:
parent
3e73f860d1
commit
e428858ad6
@ -326,8 +326,9 @@ static inline char_type
|
||||
pagerhist_remove_char(PagerHistoryBuf *ph, unsigned *count, uint8_t record[8]) {
|
||||
uint32_t codep, state = UTF8_ACCEPT;
|
||||
*count = 0;
|
||||
while (ringbuf_bytes_used(ph->ringbuf)) {
|
||||
ringbuf_memmove_from(&record[*count], ph->ringbuf, 1);
|
||||
size_t num = ringbuf_bytes_used(ph->ringbuf);
|
||||
while (num--) {
|
||||
record[*count] = ringbuf_move_char(ph->ringbuf);
|
||||
decode_utf8(&state, &codep, record[*count]);
|
||||
*count += 1;
|
||||
if (state == UTF8_REJECT) { codep = 0; break; }
|
||||
|
||||
@ -291,6 +291,18 @@ ringbuf_memmove_from(void *dst, ringbuf_t src, size_t count)
|
||||
return src->tail;
|
||||
}
|
||||
|
||||
unsigned char
|
||||
ringbuf_move_char(ringbuf_t src) {
|
||||
assert(!ringbuf_is_empty(src));
|
||||
const uint8_t *bufend = ringbuf_end(src);
|
||||
assert(bufend > src->tail);
|
||||
uint8_t ans = *src->tail;
|
||||
src->tail += 1;
|
||||
if (src->tail == bufend)
|
||||
src->tail = src->buf;
|
||||
return ans;
|
||||
}
|
||||
|
||||
size_t
|
||||
ringbuf_memcpy_from(void *dst, const ringbuf_t src, size_t count)
|
||||
{
|
||||
|
||||
@ -189,6 +189,11 @@ ringbuf_read(int fd, ringbuf_t rb, size_t count);
|
||||
void *
|
||||
ringbuf_memmove_from(void *dst, ringbuf_t src, size_t count);
|
||||
|
||||
/* ringbuf_memmove_from() optimized for a single character.
|
||||
* Must only be called if the ringbuf is not empty */
|
||||
unsigned char
|
||||
ringbuf_move_char(ringbuf_t src);
|
||||
|
||||
/*
|
||||
* Same as ringbuf_memmove_from() except that it does not change the ringbuffer
|
||||
* and returns the actual number of bytes copied, which is the minimum of ringbuf_bytes_used
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user