mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Merge pull request #957 from ailin-nemui/rawlog
Improve rawlog performance
This commit is contained in:
commit
6c40567dab
@ -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
|
||||
|
@ -41,15 +41,16 @@ 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)
|
||||
{
|
||||
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 +62,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_head(rawlog->lines);
|
||||
g_free(tmp);
|
||||
}
|
||||
|
||||
@ -75,7 +72,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_tail(rawlog->lines, 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)
|
||||
{
|
||||
GSList *tmp;
|
||||
GList *tmp;
|
||||
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));
|
||||
if (ret != -1)
|
||||
ret = write(f, "\n", 1);
|
||||
|
@ -5,8 +5,7 @@ struct _RAWLOG_REC {
|
||||
int logging;
|
||||
int handle;
|
||||
|
||||
int nlines;
|
||||
GSList *lines;
|
||||
GQueue *lines;
|
||||
};
|
||||
|
||||
RAWLOG_REC *rawlog_create(void);
|
||||
|
@ -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->head; tmp != NULL; tmp = tmp->next) {
|
||||
XPUSHs(sv_2mortal(new_pv(tmp->data)));
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user