mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-03 01:36:17 +01:00
g_logv: only expand the message once
Hoist the g_strdup_printf()'ing out of the loop, since the message is the same for every handler that gets called. https://bugzilla.gnome.org/show_bug.cgi?id=679556
This commit is contained in:
parent
f78931c4ab
commit
78a8aecbb3
@ -657,16 +657,30 @@ void
|
|||||||
g_logv (const gchar *log_domain,
|
g_logv (const gchar *log_domain,
|
||||||
GLogLevelFlags log_level,
|
GLogLevelFlags log_level,
|
||||||
const gchar *format,
|
const gchar *format,
|
||||||
va_list args1)
|
va_list args)
|
||||||
{
|
{
|
||||||
gboolean was_fatal = (log_level & G_LOG_FLAG_FATAL) != 0;
|
gboolean was_fatal = (log_level & G_LOG_FLAG_FATAL) != 0;
|
||||||
gboolean was_recursion = (log_level & G_LOG_FLAG_RECURSION) != 0;
|
gboolean was_recursion = (log_level & G_LOG_FLAG_RECURSION) != 0;
|
||||||
|
gchar buffer[1025], *msg, *msg_alloc = NULL;
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
log_level &= G_LOG_LEVEL_MASK;
|
log_level &= G_LOG_LEVEL_MASK;
|
||||||
if (!log_level)
|
if (!log_level)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (log_level & G_LOG_FLAG_RECURSION)
|
||||||
|
{
|
||||||
|
/* we use a stack buffer of fixed size, since we're likely
|
||||||
|
* in an out-of-memory situation
|
||||||
|
*/
|
||||||
|
gsize size G_GNUC_UNUSED;
|
||||||
|
|
||||||
|
size = _g_vsnprintf (buffer, 1024, format, args);
|
||||||
|
msg = buffer;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
msg = msg_alloc = g_strdup_vprintf (format, args);
|
||||||
|
|
||||||
for (i = g_bit_nth_msf (log_level, -1); i >= 0; i = g_bit_nth_msf (log_level, i))
|
for (i = g_bit_nth_msf (log_level, -1); i >= 0; i = g_bit_nth_msf (log_level, i))
|
||||||
{
|
{
|
||||||
register GLogLevelFlags test_level;
|
register GLogLevelFlags test_level;
|
||||||
@ -705,42 +719,14 @@ g_logv (const gchar *log_domain,
|
|||||||
|
|
||||||
g_private_set (&g_log_depth, GUINT_TO_POINTER (depth));
|
g_private_set (&g_log_depth, GUINT_TO_POINTER (depth));
|
||||||
|
|
||||||
|
log_func (log_domain, test_level, msg, data);
|
||||||
|
|
||||||
if (test_level & G_LOG_FLAG_RECURSION)
|
if ((test_level & G_LOG_FLAG_FATAL)
|
||||||
{
|
&& !(test_level & G_LOG_LEVEL_ERROR))
|
||||||
/* we use a stack buffer of fixed size, since we're likely
|
{
|
||||||
* in an out-of-memory situation
|
masquerade_fatal = fatal_log_func
|
||||||
*/
|
&& !fatal_log_func (log_domain, test_level, msg, fatal_log_data);
|
||||||
gchar buffer[1025];
|
}
|
||||||
gsize size G_GNUC_UNUSED;
|
|
||||||
va_list args2;
|
|
||||||
|
|
||||||
G_VA_COPY (args2, args1);
|
|
||||||
size = _g_vsnprintf (buffer, 1024, format, args2);
|
|
||||||
va_end (args2);
|
|
||||||
|
|
||||||
log_func (log_domain, test_level, buffer, data);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gchar *msg;
|
|
||||||
va_list args2;
|
|
||||||
|
|
||||||
G_VA_COPY (args2, args1);
|
|
||||||
msg = g_strdup_vprintf (format, args2);
|
|
||||||
va_end (args2);
|
|
||||||
|
|
||||||
log_func (log_domain, test_level, msg, data);
|
|
||||||
|
|
||||||
if ((test_level & G_LOG_FLAG_FATAL)
|
|
||||||
&& !(test_level & G_LOG_LEVEL_ERROR))
|
|
||||||
{
|
|
||||||
masquerade_fatal = fatal_log_func
|
|
||||||
&& !fatal_log_func (log_domain, test_level, msg, fatal_log_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((test_level & G_LOG_FLAG_FATAL) && !masquerade_fatal)
|
if ((test_level & G_LOG_FLAG_FATAL) && !masquerade_fatal)
|
||||||
{
|
{
|
||||||
@ -765,6 +751,8 @@ g_logv (const gchar *log_domain,
|
|||||||
g_private_set (&g_log_depth, GUINT_TO_POINTER (depth));
|
g_private_set (&g_log_depth, GUINT_TO_POINTER (depth));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_free (msg_alloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user