Use g_queue_clear_full().

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2019-01-13 13:20:04 +03:00
parent aa9d18e3ed
commit 7fb06b3105
3 changed files with 30 additions and 2 deletions

View File

@ -111,3 +111,28 @@ g_queue_free_full (GQueue * queue, GDestroyNotify free_func)
#endif /* ! GLIB_CHECK_VERSION (2, 32, 0) */ #endif /* ! GLIB_CHECK_VERSION (2, 32, 0) */
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
#if ! GLIB_CHECK_VERSION (2, 60, 0)
/**
* g_queue_clear_full:
* @queue: a pointer to a #GQueue
* @free_func: (nullable): the function to be called to free memory allocated
*
* Convenience method, which frees all the memory used by a #GQueue,
* and calls the provided @free_func on each item in the #GQueue.
*
* Since: 2.60
*/
void
g_queue_clear_full (GQueue * queue, GDestroyNotify free_func)
{
g_return_if_fail (queue != NULL);
if (free_func != NULL)
g_queue_foreach (queue, (GFunc) free_func, NULL);
g_queue_clear (queue);
}
#endif /* ! GLIB_CHECK_VERSION (2, 60, 0) */
/* --------------------------------------------------------------------------------------------- */

View File

@ -20,6 +20,10 @@ void g_list_free_full (GList * list, GDestroyNotify free_func);
void g_queue_free_full (GQueue * queue, GDestroyNotify free_func); void g_queue_free_full (GQueue * queue, GDestroyNotify free_func);
#endif /* ! GLIB_CHECK_VERSION (2, 32, 0) */ #endif /* ! GLIB_CHECK_VERSION (2, 32, 0) */
#if ! GLIB_CHECK_VERSION (2, 60, 0)
void g_queue_clear_full (GQueue * queue, GDestroyNotify free_func);
#endif /* ! GLIB_CHECK_VERSION (2, 60, 0) */
/*** inline functions ****************************************************************************/ /*** inline functions ****************************************************************************/
#endif /* MC_GLIBCOMPAT_H */ #endif /* MC_GLIBCOMPAT_H */

View File

@ -890,8 +890,7 @@ pop_directory (void)
static void static void
clear_stack (void) clear_stack (void)
{ {
g_queue_foreach (&dir_queue, (GFunc) vfs_path_free, NULL); g_queue_clear_full (&dir_queue, (GDestroyNotify) vfs_path_free);
g_queue_clear (&dir_queue);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */