[vlc-commits] epg: refactor creation/duplication

Francois Cartegnie git at videolan.org
Sat Feb 13 15:44:06 CET 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Feb 12 11:04:57 2016 +0100| [92c7785ba940e85f6152b0b8bc428b25e97a3f1c] | committer: Francois Cartegnie

epg: refactor creation/duplication

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=92c7785ba940e85f6152b0b8bc428b25e97a3f1c
---

 src/misc/epg.c |   52 ++++++++++++++++++++++++++++++++--------------------
 1 file changed, 32 insertions(+), 20 deletions(-)

diff --git a/src/misc/epg.c b/src/misc/epg.c
index 767fdaa..522d366 100644
--- a/src/misc/epg.c
+++ b/src/misc/epg.c
@@ -40,6 +40,30 @@ static void vlc_epg_Event_Delete( vlc_epg_event_t *p_evt )
     free( p_evt );
 }
 
+static vlc_epg_event_t * vlc_epg_Event_New( int64_t i_start, int i_duration,
+                                            const char *psz_name, const char *psz_short_description,
+                                            const char *psz_description, uint8_t i_rating )
+{
+    vlc_epg_event_t *p_evt = malloc( sizeof(*p_evt) );
+    if( likely(p_evt) )
+    {
+        p_evt->i_start = i_start;
+        p_evt->i_duration = i_duration;
+        p_evt->psz_name = psz_name ? strdup( psz_name ) : NULL;
+        p_evt->psz_short_description = psz_short_description ? strdup( psz_short_description ) : NULL;
+        p_evt->psz_description = psz_description ? strdup( psz_description ) : NULL;
+        p_evt->i_rating = i_rating;
+    }
+    return p_evt;
+}
+
+static inline vlc_epg_event_t * vlc_epg_Event_Duplicate( const vlc_epg_event_t *p_evt )
+{
+    return vlc_epg_Event_New( p_evt->i_start, p_evt->i_duration,
+                              p_evt->psz_name, p_evt->psz_short_description,
+                              p_evt->psz_description, p_evt->i_rating );
+}
+
 void vlc_epg_Init( vlc_epg_t *p_epg, const char *psz_name )
 {
     p_epg->psz_name = psz_name ? strdup( psz_name ) : NULL;
@@ -60,16 +84,11 @@ void vlc_epg_AddEvent( vlc_epg_t *p_epg, int64_t i_start, int i_duration,
                        const char *psz_name, const char *psz_short_description,
                        const char *psz_description, uint8_t i_rating )
 {
-    vlc_epg_event_t *p_evt = malloc( sizeof(*p_evt) );
-    if( !p_evt )
-        return;
-    p_evt->i_start = i_start;
-    p_evt->i_duration = i_duration;
-    p_evt->psz_name = psz_name ? strdup( psz_name ) : NULL;
-    p_evt->psz_short_description = psz_short_description ? strdup( psz_short_description ) : NULL;
-    p_evt->psz_description = psz_description ? strdup( psz_description ) : NULL;
-    p_evt->i_rating = i_rating;
-    TAB_APPEND( p_epg->i_event, p_epg->pp_event, p_evt );
+    vlc_epg_event_t *p_evt = vlc_epg_Event_New( i_start, i_duration,
+                                                psz_name, psz_short_description,
+                                                psz_description, i_rating );
+    if( likely(p_evt) )
+        TAB_APPEND( p_epg->i_event, p_epg->pp_event, p_evt );
 }
 
 vlc_epg_t *vlc_epg_New( const char *psz_name )
@@ -126,16 +145,9 @@ void vlc_epg_Merge( vlc_epg_t *p_dst, const vlc_epg_t *p_src )
         }
         if( b_add )
         {
-            vlc_epg_event_t *p_copy = calloc( 1, sizeof(vlc_epg_event_t) );
-            if( !p_copy )
-                break;
-            p_copy->i_start = p_evt->i_start;
-            p_copy->i_duration = p_evt->i_duration;
-            p_copy->psz_name = p_evt->psz_name ? strdup( p_evt->psz_name ) : NULL;
-            p_copy->psz_short_description = p_evt->psz_short_description ? strdup( p_evt->psz_short_description ) : NULL;
-            p_copy->psz_description = p_evt->psz_description ? strdup( p_evt->psz_description ) : NULL;
-            p_copy->i_rating = p_evt->i_rating;
-            TAB_INSERT( p_dst->i_event, p_dst->pp_event, p_copy, j );
+            vlc_epg_event_t *p_copy = vlc_epg_Event_Duplicate( p_evt );
+            if( likely(p_copy) )
+                TAB_INSERT( p_dst->i_event, p_dst->pp_event, p_copy, j );
         }
     }
     /* Update current */



More information about the vlc-commits mailing list