[easytag/wip/glist: 2/8] Refactor list handling in et_core.c
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/glist: 2/8] Refactor list handling in et_core.c
- Date: Thu, 23 May 2013 19:02:07 +0000 (UTC)
commit bcdb0a69ae825f0a13932714c12c9105ac317cf5
Author: David King <amigadave amigadave com>
Date: Thu May 23 19:59:37 2013 +0100
Refactor list handling in et_core.c
src/et_core.c | 101 ++++++++++++++++++++------------------------------------
1 files changed, 36 insertions(+), 65 deletions(-)
---
diff --git a/src/et_core.c b/src/et_core.c
index 0d4bbe0..709ed9c 100644
--- a/src/et_core.c
+++ b/src/et_core.c
@@ -2068,7 +2068,7 @@ gboolean ET_Set_Displayed_File_List (GList *ETFileList)
*/
gboolean ET_Free_File_List (void)
{
- g_return_val_if_fail (ETCore != NULL || ETCore->ETFileList != NULL, FALSE);
+ g_return_val_if_fail (ETCore != NULL && ETCore->ETFileList != NULL, FALSE);
g_list_free_full (ETCore->ETFileList,
(GDestroyNotify)ET_Free_File_List_Item);
@@ -2109,8 +2109,8 @@ gboolean ET_Free_File_List_Item (ET_File *ETFile)
}
g_free(ETFile->ETFileExtension);
g_free(ETFile);
- ETFile = NULL;
}
+
return TRUE;
}
@@ -2120,21 +2120,12 @@ gboolean ET_Free_File_List_Item (ET_File *ETFile)
*/
gboolean ET_Free_File_Name_List (GList *FileNameList)
{
- GList *list;
-
g_return_val_if_fail (FileNameList != NULL, FALSE);
- list = g_list_last(FileNameList);
- while (list)
- {
- if ( (File_Name *)list->data )
- ET_Free_File_Name_Item( (File_Name *)list->data );
+ FileNameList = g_list_first (FileNameList);
+
+ g_list_free_full (FileNameList, (GDestroyNotify)ET_Free_File_Name_Item);
- if (!list->prev) break;
- list = list->prev;
- }
- g_list_free(list);
- FileNameList = NULL;
return TRUE;
}
@@ -2150,7 +2141,7 @@ gboolean ET_Free_File_Name_Item (File_Name *FileName)
g_free(FileName->value_utf8);
g_free(FileName->value_ck);
g_free(FileName);
- FileName = NULL;
+
return TRUE;
}
@@ -2161,21 +2152,20 @@ gboolean ET_Free_File_Name_Item (File_Name *FileName)
static gboolean
ET_Free_File_Tag_List (GList *FileTagList)
{
- GList *list;
+ GList *l;
g_return_val_if_fail (FileTagList != NULL, FALSE);
- list = g_list_last(FileTagList);
- while (list)
- {
- if ( (File_Tag *)list->data )
- ET_Free_File_Tag_Item( (File_Tag *)list->data );
+ FileTagList = g_list_first (FileTagList);
- if (!list->prev) break;
- list = list->prev;
+ for (l = FileTagList; l != NULL; l = g_list_next (l))
+ {
+ if ((File_Tag *)l->data)
+ ET_Free_File_Tag_Item ((File_Tag *)l->data);
}
- g_list_free(list);
- FileTagList = NULL;
+
+ g_list_free (FileTagList);
+
return TRUE;
}
@@ -2186,16 +2176,7 @@ ET_Free_File_Tag_List (GList *FileTagList)
static gboolean
ET_Free_File_Tag_Item_Other_Field (File_Tag *FileTag)
{
- GList *other = FileTag->other;
-
- while (other)
- {
- g_free(other->data);
-
- if (!other->next) break;
- other = other->next;
- }
- g_list_free(FileTag->other);
+ g_list_free_full (FileTag->other, g_free);
return TRUE;
}
@@ -2256,22 +2237,15 @@ ET_Free_File_Info_Item (ET_File_Info *ETFileInfo)
static gboolean
ET_Free_History_File_List (void)
{
- GList *list;
-
- g_return_val_if_fail (ETCore != NULL || ETCore->ETHistoryFileList != NULL,
+ g_return_val_if_fail (ETCore != NULL && ETCore->ETHistoryFileList != NULL,
FALSE);
- ETCore->ETHistoryFileList = g_list_first(ETCore->ETHistoryFileList);
- list = ETCore->ETHistoryFileList;
- while (list)
- {
- g_free( (ET_History_File *)list->data );
+ ETCore->ETHistoryFileList = g_list_first (ETCore->ETHistoryFileList);
+
+ g_list_free_full (ETCore->ETHistoryFileList, g_free);
- if (!list->next) break;
- list = list->next;
- }
- g_list_free(ETCore->ETHistoryFileList);
ETCore->ETHistoryFileList = NULL;
+
return TRUE;
}
@@ -2281,8 +2255,8 @@ ET_Free_History_File_List (void)
static gboolean
ET_Free_Displayed_File_List (void)
{
- g_return_val_if_fail (ETCore != NULL ||
- ETCore->ETFileDisplayedList != NULL, FALSE);
+ g_return_val_if_fail (ETCore != NULL
+ && ETCore->ETFileDisplayedList != NULL, FALSE);
ETCore->ETFileDisplayedList = g_list_first(ETCore->ETFileDisplayedList);
ETCore->ETFileDisplayedList = NULL;
@@ -2297,29 +2271,26 @@ ET_Free_Displayed_File_List (void)
static gboolean
ET_Free_Artist_Album_File_List (void)
{
- GList *ArtistList;
- GList *AlbumList;
- GList *etfilelist;
+ GList *l;
- g_return_val_if_fail (ETCore != NULL ||
- ETCore->ETArtistAlbumFileList != NULL, FALSE);
+ g_return_val_if_fail (ETCore != NULL
+ && ETCore->ETArtistAlbumFileList != NULL, FALSE);
- ArtistList = ETCore->ETArtistAlbumFileList;
- while (ArtistList)
+ for (l = ETCore->ETArtistAlbumFileList; l != NULL; l = g_list_next (l))
{
- AlbumList = (GList *)ArtistList->data;
- while (AlbumList)
+ GList *m;
+
+ for (m = (GList *)l->data; m != NULL; m = g_list_next (m))
{
- etfilelist = (GList *)AlbumList->data;
- if (etfilelist)
- g_list_free(etfilelist);
- AlbumList = AlbumList->next;
+ GList *n = (GList *)m->data;
+ if (n)
+ g_list_free (n);
}
- if (ArtistList->data) // Free AlbumList list
- g_list_free((GList *)ArtistList->data);
- ArtistList = ArtistList->next;
+ if (l->data) /* Free AlbumList list. */
+ g_list_free ((GList *)l->data);
}
+
if (ETCore->ETArtistAlbumFileList)
g_list_free(ETCore->ETArtistAlbumFileList);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]