1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

improve rawlog perf

This commit is contained in:
ailin-nemui 2018-10-04 09:21:46 +02:00
parent f5e587a83b
commit 05fd64dd16
3 changed files with 9 additions and 14 deletions

View File

@ -48,8 +48,8 @@ void rawlog_destroy(RAWLOG_REC *rawlog)
{ {
g_return_if_fail(rawlog != NULL); g_return_if_fail(rawlog != NULL);
g_slist_foreach(rawlog->lines, (GFunc) g_free, NULL); g_queue_foreach(rawlog->lines, (GFunc) g_free, NULL);
g_slist_free(rawlog->lines); g_queue_free(rawlog->lines);
if (rawlog->logging) { if (rawlog->logging) {
write_buffer_flush(); write_buffer_flush();
@ -61,12 +61,8 @@ void rawlog_destroy(RAWLOG_REC *rawlog)
/* NOTE! str must be dynamically allocated and must not be freed after! */ /* NOTE! str must be dynamically allocated and must not be freed after! */
static void rawlog_add(RAWLOG_REC *rawlog, char *str) static void rawlog_add(RAWLOG_REC *rawlog, char *str)
{ {
if (rawlog->nlines < rawlog_lines || rawlog_lines <= 2) if (rawlog->lines->length >= rawlog_lines && rawlog_lines > 0) {
rawlog->nlines++; void *tmp = g_queue_pop_tail(rawlog->lines);
else {
void *tmp = rawlog->lines->data;
rawlog->lines = g_slist_remove(rawlog->lines,
rawlog->lines->data);
g_free(tmp); g_free(tmp);
} }
@ -75,7 +71,7 @@ static void rawlog_add(RAWLOG_REC *rawlog, char *str)
write_buffer(rawlog->handle, "\n", 1); write_buffer(rawlog->handle, "\n", 1);
} }
rawlog->lines = g_slist_append(rawlog->lines, str); g_queue_push_head(rawlog->lines, str);
signal_emit_id(signal_rawlog, 2, rawlog, str); signal_emit_id(signal_rawlog, 2, rawlog, str);
} }
@ -105,10 +101,10 @@ void rawlog_redirect(RAWLOG_REC *rawlog, const char *str)
static void rawlog_dump(RAWLOG_REC *rawlog, int f) static void rawlog_dump(RAWLOG_REC *rawlog, int f)
{ {
GSList *tmp; GList *tmp;
ssize_t ret = 0; ssize_t ret = 0;
for (tmp = rawlog->lines; ret != -1 && tmp != NULL; tmp = tmp->next) { for (tmp = rawlog->lines->tail; ret != -1 && tmp != NULL; tmp = tmp->prev) {
ret = write(f, tmp->data, strlen((char *) tmp->data)); ret = write(f, tmp->data, strlen((char *) tmp->data));
if (ret != -1) if (ret != -1)
ret = write(f, "\n", 1); ret = write(f, "\n", 1);

View File

@ -5,8 +5,7 @@ struct _RAWLOG_REC {
int logging; int logging;
int handle; int handle;
int nlines; GQueue *lines;
GSList *lines;
}; };
RAWLOG_REC *rawlog_create(void); RAWLOG_REC *rawlog_create(void);

View File

@ -501,7 +501,7 @@ static void perl_log_item_fill_hash(HV *hv, LOG_ITEM_REC *item)
static void perl_rawlog_fill_hash(HV *hv, RAWLOG_REC *rawlog) static void perl_rawlog_fill_hash(HV *hv, RAWLOG_REC *rawlog)
{ {
(void) hv_store(hv, "logging", 7, newSViv(rawlog->logging), 0); (void) hv_store(hv, "logging", 7, newSViv(rawlog->logging), 0);
(void) hv_store(hv, "nlines", 6, newSViv(rawlog->nlines), 0); (void) hv_store(hv, "nlines", 6, newSViv(rawlog->lines->length), 0);
} }
static void perl_reconnect_fill_hash(HV *hv, RECONNECT_REC *reconnect) static void perl_reconnect_fill_hash(HV *hv, RECONNECT_REC *reconnect)