1
0
mirror of https://github.com/irssi/irssi.git synced 2024-10-13 05:03:45 -04:00

Merge pull request #957 from ailin-nemui/rawlog

Improve rawlog performance
This commit is contained in:
ailin-nemui 2018-11-12 13:02:41 +01:00 committed by GitHub
commit 6c40567dab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 18 deletions

View File

@ -6,7 +6,7 @@
#define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */ #define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */
#define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */ #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_PORT 6667
#define DEFAULT_SERVER_ADD_TLS_PORT 6697 #define DEFAULT_SERVER_ADD_TLS_PORT 6697

View File

@ -41,15 +41,16 @@ RAWLOG_REC *rawlog_create(void)
RAWLOG_REC *rec; RAWLOG_REC *rec;
rec = g_new0(RAWLOG_REC, 1); rec = g_new0(RAWLOG_REC, 1);
return rec; rec->lines = g_queue_new();
return rec;
} }
void rawlog_destroy(RAWLOG_REC *rawlog) 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 +62,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_head(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 +72,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_tail(rawlog->lines, str);
signal_emit_id(signal_rawlog, 2, rawlog, str); signal_emit_id(signal_rawlog, 2, rawlog, str);
} }
@ -105,10 +102,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->head; ret != -1 && tmp != NULL; tmp = tmp->next) {
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

@ -19,9 +19,9 @@ void
rawlog_get_lines(rawlog) rawlog_get_lines(rawlog)
Irssi::Rawlog rawlog Irssi::Rawlog rawlog
PREINIT: PREINIT:
GSList *tmp; GList *tmp;
PPCODE: PPCODE:
for (tmp = rawlog->lines; tmp != NULL; tmp = tmp->next) { for (tmp = rawlog->lines->head; tmp != NULL; tmp = tmp->next) {
XPUSHs(sv_2mortal(new_pv(tmp->data))); XPUSHs(sv_2mortal(new_pv(tmp->data)));
} }

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)