Minor xrdb buffer optimization

This commit is contained in:
Francesco Abbate 2021-03-18 10:06:01 +01:00
parent 43e08b0f8e
commit a742c56ee7
1 changed files with 4 additions and 5 deletions

View File

@ -68,15 +68,14 @@ static int xrdb_try_dpi_match(const char *line, int len) {
return -1; return -1;
} }
#define XRDB_READ_BUF_SIZE 256 static void xrdb_complete_reading(int read_fd, char *buf, size_t buf_size) {
static void xrdb_complete_reading(int read_fd) {
char buf[XRDB_READ_BUF_SIZE];
while (1) { while (1) {
int nr = read(read_fd, buf, XRDB_READ_BUF_SIZE); int nr = read(read_fd, buf, buf_size);
if (nr <= 0) return; if (nr <= 0) return;
} }
} }
#define XRDB_READ_BUF_SIZE 256
static int xrdb_parse_for_dpi(int read_fd) { static int xrdb_parse_for_dpi(int read_fd) {
char buf[XRDB_READ_BUF_SIZE]; char buf[XRDB_READ_BUF_SIZE];
char buf_remaining = 0; char buf_remaining = 0;
@ -93,7 +92,7 @@ static int xrdb_parse_for_dpi(int read_fd) {
if (nlptr < buf_limit) { if (nlptr < buf_limit) {
int dpi_read = xrdb_try_dpi_match(line_start, nlptr - line_start); int dpi_read = xrdb_try_dpi_match(line_start, nlptr - line_start);
if (dpi_read > 0) { if (dpi_read > 0) {
xrdb_complete_reading(read_fd); xrdb_complete_reading(read_fd, buf, XRDB_READ_BUF_SIZE);
return dpi_read; return dpi_read;
} }
/* doesn't match: position after newline to search again */ /* doesn't match: position after newline to search again */