]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
epg: optimization save 3 pointers to function from all epg objects
authorJaroslav Kysela <perex@perex.cz>
Tue, 6 Dec 2016 10:42:11 +0000 (11:42 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 6 Dec 2016 10:42:11 +0000 (11:42 +0100)
src/dvr/dvr_autorec.c
src/dvr/dvr_db.c
src/epg.c
src/epg.h

index d22619913d5d1fa5122bf029563475b0e2135ec0..b4292813d8c1750c178bcab0d84ab890a2c94971 100644 (file)
@@ -409,11 +409,11 @@ autorec_entry_destroy(dvr_autorec_entry_t *dae, int delconf)
     LIST_REMOVE(dae, dae_channel_tag_link);
 
   if(dae->dae_brand)
-    dae->dae_brand->putref(dae->dae_brand);
+    dae->dae_brand->ops->putref(dae->dae_brand);
   if(dae->dae_season)
-    dae->dae_season->putref(dae->dae_season);
+    dae->dae_season->ops->putref(dae->dae_season);
   if(dae->dae_serieslink)
-    dae->dae_serieslink->putref(dae->dae_serieslink);
+    dae->dae_serieslink->ops->putref(dae->dae_serieslink);
 
   free(dae);
 }
@@ -825,12 +825,12 @@ dvr_autorec_entry_class_brand_set(void *o, const void *v)
   brand = v ? epg_brand_find_by_uri(v, NULL, 1, &save, NULL) : NULL;
   if (brand && dae->dae_brand != brand) {
     if (dae->dae_brand)
-      dae->dae_brand->putref((epg_object_t*)dae->dae_brand);
-    brand->getref((epg_object_t*)brand);
+      dae->dae_brand->ops->putref((epg_object_t*)dae->dae_brand);
+    brand->ops->getref((epg_object_t*)brand);
     dae->dae_brand = brand;
     return 1;
   } else if (brand == NULL && dae->dae_brand) {
-    dae->dae_brand->putref((epg_object_t*)dae->dae_brand);
+    dae->dae_brand->ops->putref((epg_object_t*)dae->dae_brand);
     dae->dae_brand = NULL;
     return 1;
   }
@@ -861,12 +861,12 @@ dvr_autorec_entry_class_season_set(void *o, const void *v)
   season = v ? epg_season_find_by_uri(v, NULL, 1, &save, NULL) : NULL;
   if (season && dae->dae_season != season) {
     if (dae->dae_season)
-      dae->dae_season->putref((epg_object_t*)dae->dae_season);
-    season->getref((epg_object_t*)season);
+      dae->dae_season->ops->putref((epg_object_t*)dae->dae_season);
+    season->ops->getref((epg_object_t*)season);
     dae->dae_season = season;
     return 1;
   } else if (season == NULL && dae->dae_season) {
-    dae->dae_season->putref((epg_object_t*)dae->dae_season);
+    dae->dae_season->ops->putref((epg_object_t*)dae->dae_season);
     dae->dae_season = NULL;
     return 1;
   }
@@ -897,12 +897,12 @@ dvr_autorec_entry_class_series_link_set(void *o, const void *v)
   sl = v ? epg_serieslink_find_by_uri(v, NULL, 1, &save, NULL) : NULL;
   if (sl && dae->dae_serieslink != sl) {
     if (dae->dae_serieslink)
-      dae->dae_serieslink->putref((epg_object_t*)dae->dae_season);
-    sl->getref((epg_object_t*)sl);
+      dae->dae_serieslink->ops->putref((epg_object_t*)dae->dae_season);
+    sl->ops->getref((epg_object_t*)sl);
     dae->dae_serieslink = sl;
     return 1;
   } else if (sl == NULL && dae->dae_serieslink) {
-    dae->dae_season->putref((epg_object_t*)dae->dae_season);
+    dae->dae_season->ops->putref((epg_object_t*)dae->dae_season);
     dae->dae_season = NULL;
     return 1;
   }
index 41ec41983449b29ec5c3d7856c8af1bcda567d63..dfa0b13a225942d38417c622db7b4eae406b0742 100644 (file)
@@ -222,13 +222,13 @@ dvr_entry_assign_broadcast(dvr_entry_t *de, epg_broadcast_t *bcast)
     if (de->de_bcast) {
       snprintf(id, sizeof(id), "%u", de->de_bcast->id);
       dvr_entry_trace(de, "unassign broadcast %s", id);
-      de->de_bcast->putref((epg_object_t*)de->de_bcast);
+      de->de_bcast->ops->putref((epg_object_t*)de->de_bcast);
       notify_delayed(id, "epg", "dvr_delete");
       de->de_bcast = NULL;
       de->de_dvb_eid = 0;
     }
     if (bcast) {
-      bcast->getref((epg_object_t*)bcast);
+      bcast->ops->getref((epg_object_t*)bcast);
       de->de_bcast = bcast;
       snprintf(id, sizeof(id), "%u", bcast->id);
       dvr_entry_trace(de, "assign broadcast %s", id);
index 4275bcbfcb0a54bc2e3a849c4980678c590bec13..1e898d74cbab2348a6b7edecdcfd5b291bfa5f44 100644 (file)
--- a/src/epg.c
+++ b/src/epg.c
@@ -125,7 +125,7 @@ void epg_updated ( void )
     tvhtrace(LS_EPG,
              "unref'd object %u (%s) created during update", eo->id, eo->uri);
     LIST_REMOVE(eo, un_link);
-    eo->destroy(eo);
+    eo->ops->destroy(eo);
   }
   // Note: we do things this way around since unref'd objects are not likely
   //       to be useful to DVR since they will relate to episode/seasons/brands
@@ -133,7 +133,7 @@ void epg_updated ( void )
 
   /* Update updated */
   while ((eo = LIST_FIRST(&epg_object_updated))) {
-    eo->update(eo);
+    eo->ops->update(eo);
     LIST_REMOVE(eo, up_link);
     eo->_updated = 0;
     eo->_created = 1;
@@ -173,7 +173,7 @@ static int _epg_object_putref ( void *o )
   assert(eo->refcount>0);
   eo->refcount--;
   if (!eo->refcount) {
-    eo->destroy(eo);
+    eo->ops->destroy(eo);
     return 1;
   }
   return 0;
@@ -219,8 +219,6 @@ static void _epg_object_create ( void *o )
   uint32_t id = eo->id;
   if (!id) eo->id = ++_epg_object_idx;
   if (!eo->id) eo->id = ++_epg_object_idx;
-  if (!eo->getref) eo->getref = _epg_object_getref;
-  if (!eo->putref) eo->putref = _epg_object_putref;
   tvhtrace(LS_EPG, "eo [%p, %u, %d, %s] created",
            eo, eo->id, eo->type, eo->uri);
   _epg_object_set_updated(eo);
@@ -458,14 +456,20 @@ static void _epg_brand_updated ( void *o )
   dvr_autorec_check_brand((epg_brand_t*)o);
 }
 
+static epg_object_ops_t _epg_brand_ops = {
+  .getref  = _epg_object_getref,
+  .putref  = _epg_object_putref,
+  .destroy = _epg_brand_destroy,
+  .update  = _epg_brand_updated,
+};
+
 static epg_object_t **_epg_brand_skel ( void )
 {
   static epg_object_t *skel = NULL;
   if (!skel) {
     skel = calloc(1, sizeof(epg_brand_t));
-    skel->type    = EPG_BRAND;
-    skel->destroy = _epg_brand_destroy;
-    skel->update  = _epg_brand_updated;
+    skel->type = EPG_BRAND;
+    skel->ops  = &_epg_brand_ops;
   }
   return &skel;
 }
@@ -665,14 +669,20 @@ static void _epg_season_updated ( void *eo )
   dvr_autorec_check_season((epg_season_t*)eo);
 }
 
+static epg_object_ops_t _epg_season_ops = {
+  .getref  = _epg_object_getref,
+  .putref  = _epg_object_putref,
+  .destroy = _epg_season_destroy,
+  .update  = _epg_season_updated,
+};
+
 static epg_object_t **_epg_season_skel ( void )
 {
   static epg_object_t *skel = NULL;
   if (!skel) {
     skel = calloc(1, sizeof(epg_season_t));
-    skel->type    = EPG_SEASON;
-    skel->destroy = _epg_season_destroy;
-    skel->update  = _epg_season_updated;
+    skel->type = EPG_SEASON;
+    skel->ops  = &_epg_season_ops;
   }
   return &skel;
 }
@@ -919,14 +929,20 @@ static void _epg_episode_updated ( void *eo )
 {
 }
 
+static epg_object_ops_t _epg_episode_ops = {
+  .getref  = _epg_object_getref,
+  .putref  = _epg_object_putref,
+  .destroy = _epg_episode_destroy,
+  .update  = _epg_episode_updated,
+};
+
 static epg_object_t **_epg_episode_skel ( void )
 {
   static epg_object_t *skel = NULL;
   if (!skel) {
     skel = calloc(1, sizeof(epg_episode_t));
-    skel->type    = EPG_EPISODE;
-    skel->destroy = _epg_episode_destroy;
-    skel->update  = _epg_episode_updated;
+    skel->type = EPG_EPISODE;
+    skel->ops  = &_epg_episode_ops;
   }
   return &skel;
 }
@@ -1461,14 +1477,20 @@ static void _epg_serieslink_updated ( void *eo )
   dvr_autorec_check_serieslink((epg_serieslink_t*)eo);
 }
 
+static epg_object_ops_t _epg_serieslink_ops = {
+  .getref  = _epg_object_getref,
+  .putref  = _epg_object_putref,
+  .destroy = _epg_serieslink_destroy,
+  .update  = _epg_serieslink_updated,
+};
+
 static epg_object_t **_epg_serieslink_skel ( void )
 {
   static epg_object_t *skel = NULL;
   if (!skel) {
     skel = calloc(1, sizeof(epg_serieslink_t));
-    skel->type    = EPG_SERIESLINK;
-    skel->destroy = _epg_serieslink_destroy;
-    skel->update  = _epg_serieslink_updated;
+    skel->type = EPG_SERIESLINK;
+    skel->ops  = &_epg_serieslink_ops;
   }
   return &skel;
 }
@@ -1567,10 +1589,10 @@ static void _epg_channel_timer_callback ( void *p )
       gtimer_arm_rel(&ch->ch_epg_timer, _epg_channel_timer_callback, ch, 2);
       return;
     }
-    cur->getref(cur);
+    cur->ops->getref(cur);
   }
   if ((nxt = ch->ch_epg_next))
-    nxt->getref(nxt);
+    nxt->ops->getref(nxt);
   ch->ch_epg_now = ch->ch_epg_next = NULL;
 
   /* Check events */
@@ -1617,8 +1639,8 @@ static void _epg_channel_timer_callback ( void *p )
   }
 
   /* Remove refs */
-  if (cur) cur->putref(cur);
-  if (nxt) nxt->putref(nxt);
+  if (cur) cur->ops->putref(cur);
+  if (nxt) nxt->ops->putref(nxt);
 }
 
 static epg_broadcast_t *_epg_channel_add_broadcast 
@@ -1755,9 +1777,9 @@ static epg_broadcast_t *_epg_channel_add_broadcast
   }
 
   /* Reset timer - it might free return event! */
-  ret->getref(ret);
+  ret->ops->getref(ret);
   if (timer) _epg_channel_timer_callback(ch);
-  if (ret->putref(ret)) return NULL;
+  if (ret->ops->putref(ret)) return NULL;
   return ret;
 }
 
@@ -1815,14 +1837,20 @@ static void _epg_broadcast_updated ( void *eo )
   }
 }
 
+static epg_object_ops_t _epg_broadcast_ops = {
+  .getref  = _epg_object_getref,
+  .putref  = _epg_object_putref,
+  .destroy = _epg_broadcast_destroy,
+  .update  = _epg_broadcast_updated,
+};
+
 static epg_broadcast_t **_epg_broadcast_skel ( void )
 {
   static epg_broadcast_t *skel = NULL;
   if (!skel) {
     skel = calloc(1, sizeof(epg_broadcast_t));
-    skel->type    = EPG_BROADCAST;
-    skel->destroy = _epg_broadcast_destroy;
-    skel->update  = _epg_broadcast_updated;
+    skel->type = EPG_BROADCAST;
+    skel->ops  = &_epg_broadcast_ops;
   }
   return &skel;
 }
index f7f4601ecbfede01a58e621e6f722be169945fbb..4d2d65e5bd669989abcaa614c3bebda4d15e6aa6 100644 (file)
--- a/src/epg.h
+++ b/src/epg.h
@@ -128,6 +128,13 @@ typedef enum epg_object_type
 #define EPG_CHANGED_IMAGE         (1<<5)
 #define EPG_CHANGED_SLAST         2
 
+typedef struct epg_object_ops {
+  void (*getref)  ( void *o );        ///< Get a reference
+  int  (*putref)  ( void *o );               ///< Release a reference
+  void (*destroy) ( void *o );        ///< Delete the object
+  void (*update)  ( void *o );        ///< Updated
+} epg_object_ops_t;
+
 /* Object */
 struct epg_object
 {
@@ -148,10 +155,7 @@ struct epg_object
 
   struct epggrab_module  *grabber;    ///< Originating grabber
 
-  void (*getref)  ( void *o );        ///< Get a reference
-  int  (*putref)  ( void *o );               ///< Release a reference
-  void (*destroy) ( void *o );        ///< Delete the object
-  void (*update)  ( void *o );        ///< Updated
+  epg_object_ops_t       *ops;        ///< Operations on the object
 };
 
 /* Get an object by ID (special case usage) */