From 05fd64dd1611610e2efe596718c657343db839e1 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Thu, 4 Oct 2018 09:21:46 +0200 Subject: [PATCH 1/5] improve rawlog perf --- src/core/rawlog.c | 18 +++++++----------- src/core/rawlog.h | 3 +-- src/perl/perl-common.c | 2 +- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/core/rawlog.c b/src/core/rawlog.c index e6bb7017..8f2d7142 100644 --- a/src/core/rawlog.c +++ b/src/core/rawlog.c @@ -48,8 +48,8 @@ void rawlog_destroy(RAWLOG_REC *rawlog) { g_return_if_fail(rawlog != NULL); - g_slist_foreach(rawlog->lines, (GFunc) g_free, NULL); - g_slist_free(rawlog->lines); + g_queue_foreach(rawlog->lines, (GFunc) g_free, NULL); + g_queue_free(rawlog->lines); if (rawlog->logging) { 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! */ static void rawlog_add(RAWLOG_REC *rawlog, char *str) { - if (rawlog->nlines < rawlog_lines || rawlog_lines <= 2) - rawlog->nlines++; - else { - void *tmp = rawlog->lines->data; - rawlog->lines = g_slist_remove(rawlog->lines, - rawlog->lines->data); + if (rawlog->lines->length >= rawlog_lines && rawlog_lines > 0) { + void *tmp = g_queue_pop_tail(rawlog->lines); g_free(tmp); } @@ -75,7 +71,7 @@ static void rawlog_add(RAWLOG_REC *rawlog, char *str) 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); } @@ -105,10 +101,10 @@ void rawlog_redirect(RAWLOG_REC *rawlog, const char *str) static void rawlog_dump(RAWLOG_REC *rawlog, int f) { - GSList *tmp; + GList *tmp; 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)); if (ret != -1) ret = write(f, "\n", 1); diff --git a/src/core/rawlog.h b/src/core/rawlog.h index 9e460a83..01175e67 100644 --- a/src/core/rawlog.h +++ b/src/core/rawlog.h @@ -5,8 +5,7 @@ struct _RAWLOG_REC { int logging; int handle; - int nlines; - GSList *lines; + GQueue *lines; }; RAWLOG_REC *rawlog_create(void); diff --git a/src/perl/perl-common.c b/src/perl/perl-common.c index 1d08319f..802a771e 100644 --- a/src/perl/perl-common.c +++ b/src/perl/perl-common.c @@ -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) { (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) From 95692d4d86c4a39697d16e937a452a662e6ba448 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Thu, 4 Oct 2018 09:21:54 +0200 Subject: [PATCH 2/5] up abi --- src/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.h b/src/common.h index 8d4da02f..c8fb54df 100644 --- a/src/common.h +++ b/src/common.h @@ -6,7 +6,7 @@ #define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */ #define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */ -#define IRSSI_ABI_VERSION 17 +#define IRSSI_ABI_VERSION 18 #define DEFAULT_SERVER_ADD_PORT 6667 #define DEFAULT_SERVER_ADD_TLS_PORT 6697 From ff0daf5870909b250e377ffa438c4fe0ebc2f8ce Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Thu, 4 Oct 2018 09:31:08 +0200 Subject: [PATCH 3/5] actually create the queue, too --- src/core/rawlog.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/rawlog.c b/src/core/rawlog.c index 8f2d7142..dafad057 100644 --- a/src/core/rawlog.c +++ b/src/core/rawlog.c @@ -41,7 +41,8 @@ RAWLOG_REC *rawlog_create(void) RAWLOG_REC *rec; rec = g_new0(RAWLOG_REC, 1); - return rec; + rec->lines = g_queue_new(); + return rec; } void rawlog_destroy(RAWLOG_REC *rawlog) From 1e2547eb92e8a681540925a0da3867a879afd696 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Thu, 4 Oct 2018 09:33:07 +0200 Subject: [PATCH 4/5] fixup perl side --- src/perl/common/Rawlog.xs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/perl/common/Rawlog.xs b/src/perl/common/Rawlog.xs index c405bc37..73845287 100644 --- a/src/perl/common/Rawlog.xs +++ b/src/perl/common/Rawlog.xs @@ -19,9 +19,9 @@ void rawlog_get_lines(rawlog) Irssi::Rawlog rawlog PREINIT: - GSList *tmp; + GList *tmp; PPCODE: - for (tmp = rawlog->lines; tmp != NULL; tmp = tmp->next) { + for (tmp = rawlog->lines->tail; tmp != NULL; tmp = tmp->prev) { XPUSHs(sv_2mortal(new_pv(tmp->data))); } From 4537d85b0b1e3bbd5240e379d015752423381e9a Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Fri, 9 Nov 2018 11:32:00 +0100 Subject: [PATCH 5/5] reverse queue --- src/core/rawlog.c | 6 +++--- src/perl/common/Rawlog.xs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/rawlog.c b/src/core/rawlog.c index dafad057..e0c4dd3d 100644 --- a/src/core/rawlog.c +++ b/src/core/rawlog.c @@ -63,7 +63,7 @@ void rawlog_destroy(RAWLOG_REC *rawlog) static void rawlog_add(RAWLOG_REC *rawlog, char *str) { if (rawlog->lines->length >= rawlog_lines && rawlog_lines > 0) { - void *tmp = g_queue_pop_tail(rawlog->lines); + void *tmp = g_queue_pop_head(rawlog->lines); g_free(tmp); } @@ -72,7 +72,7 @@ static void rawlog_add(RAWLOG_REC *rawlog, char *str) write_buffer(rawlog->handle, "\n", 1); } - g_queue_push_head(rawlog->lines, str); + g_queue_push_tail(rawlog->lines, str); signal_emit_id(signal_rawlog, 2, rawlog, str); } @@ -105,7 +105,7 @@ static void rawlog_dump(RAWLOG_REC *rawlog, int f) GList *tmp; ssize_t ret = 0; - for (tmp = rawlog->lines->tail; ret != -1 && tmp != NULL; tmp = tmp->prev) { + for (tmp = rawlog->lines->head; ret != -1 && tmp != NULL; tmp = tmp->next) { ret = write(f, tmp->data, strlen((char *) tmp->data)); if (ret != -1) ret = write(f, "\n", 1); diff --git a/src/perl/common/Rawlog.xs b/src/perl/common/Rawlog.xs index 73845287..3c946c7e 100644 --- a/src/perl/common/Rawlog.xs +++ b/src/perl/common/Rawlog.xs @@ -21,7 +21,7 @@ rawlog_get_lines(rawlog) PREINIT: GList *tmp; PPCODE: - for (tmp = rawlog->lines->tail; tmp != NULL; tmp = tmp->prev) { + for (tmp = rawlog->lines->head; tmp != NULL; tmp = tmp->next) { XPUSHs(sv_2mortal(new_pv(tmp->data))); }