Welcome to little lamb

Code » slicd » commit eab5715

Don't use a bit to store days_combo flag

author Olivier Brunel
2016-05-28 13:22:06 UTC
committer Olivier Brunel
2016-05-28 13:22:06 UTC
parent 74af741384f7299eed179140ac800e9365fa3761

Don't use a bit to store days_combo flag

We can simply check for restrictions on both DOW & DAYS to determine whether
it's enabled or not, thus freeing a bit in slicd_job_t.

src/include/slicd/fields.h +2 -3
src/include/slicd/job.h +0 -3
src/libslicd/slicd_job.c +4 -11
src/libslicd/slicd_job_ensure_valid.c +1 -8

diff --git a/src/include/slicd/fields.h b/src/include/slicd/fields.h
index 06c18e2..cf686f3 100644
--- a/src/include/slicd/fields.h
+++ b/src/include/slicd/fields.h
@@ -29,8 +29,8 @@
  * 31   days (0-30)
  * 12   months (0-11)
  *  7   days of week (0-6; 0=sunday, 1=monday, etc)
- *  1   days combo: set when both days & dow are set, i.e. the Nth dow
  *  1   special DST: to enable special handling for DST changes
+ *  1   unused
  *
  * 136 bits total; hence an array of 17 char-s
  *
@@ -42,8 +42,7 @@
 #define _SLICD_BITS_OFFSET_DAYS         _SLICD_BITS_OFFSET_HOURS + 24
 #define _SLICD_BITS_OFFSET_MONTHS       _SLICD_BITS_OFFSET_DAYS + 31
 #define _SLICD_BITS_OFFSET_DOW          _SLICD_BITS_OFFSET_MONTHS + 12
-#define _SLICD_BIT_DAYS_COMBO           _SLICD_BITS_OFFSET_DOW + 7
-#define _SLICD_BIT_DST_SPECIAL          _SLICD_BIT_DAYS_COMBO + 1
+#define _SLICD_BIT_DST_SPECIAL          _SLICD_BITS_OFFSET_DOW + 7
 
 static struct
 {
diff --git a/src/include/slicd/job.h b/src/include/slicd/job.h
index 1d410ce..35526ef 100644
--- a/src/include/slicd/job.h
+++ b/src/include/slicd/job.h
@@ -48,9 +48,6 @@ extern int slicd_job_has            (slicd_job_t    *job,
 
 extern int slicd_job_has_days_combo (slicd_job_t    *job);
 
-extern int slicd_job_set_days_combo (slicd_job_t    *job,
-                                     int             what);
-
 extern int slicd_job_has_dst_special(slicd_job_t    *job);
 
 extern int slicd_job_set_dst_special(slicd_job_t    *job,
diff --git a/src/libslicd/slicd_job.c b/src/libslicd/slicd_job.c
index f81fe86..ff69b25 100644
--- a/src/libslicd/slicd_job.c
+++ b/src/libslicd/slicd_job.c
@@ -51,17 +51,10 @@ int
 slicd_job_has_days_combo (slicd_job_t    *job)
 {
     assert (job != NULL);
-    return bitarray_isset (job->bits, _SLICD_BIT_DAYS_COMBO);
-}
-
-int
-slicd_job_set_days_combo (slicd_job_t    *job,
-                          int             what)
-{
-    assert (job != NULL);
-
-    bitarray_clearsetn (job->bits, _SLICD_BIT_DAYS_COMBO, 1, what);
-    return 0;
+    return slicd_job_first (job, SLICD_DAYS_OF_WEEK, 0, 6, 0) <= 6
+        /* we're assuming job is valid, i.e. went through
+         * slicd_job_ensure_valid() */
+        && slicd_job_first (job, SLICD_DAYS, 1, 6, 0) <= 6;
 }
 
 int
diff --git a/src/libslicd/slicd_job_ensure_valid.c b/src/libslicd/slicd_job_ensure_valid.c
index 867dace..d4f1474 100644
--- a/src/libslicd/slicd_job_ensure_valid.c
+++ b/src/libslicd/slicd_job_ensure_valid.c
@@ -43,21 +43,14 @@ slicd_job_ensure_valid (slicd_job_t *job)
          * are set:
          * - all set    = same as '*', no restriction on DAYS
          * - none set   = invalid
-         * - a mix      = DAYS_COMBO
+         * ( a mix      = DAYS_COMBO )
          */
 
         if (slicd_job_first (job, SLICD_DAYS, 1, 6, 0) == 7)
-        {
             slicd_job_set (job, SLICD_DAYS, 1, 31);
-            slicd_job_set_days_combo (job, 0);
-        }
         else if (slicd_job_first (job, SLICD_DAYS, 1, 6, 1) == 7)
             return -SLICD_ERR_DAYS_COMBO;
-        else
-            slicd_job_set_days_combo (job, 1);
     }
-    else
-        slicd_job_set_days_combo (job, 0);
 
     /* ensure date validity/coherence */
     if (slicd_job_first (job, SLICD_DAYS, 1, 29, 1) == 30)