]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - mood.c
Merge branch 'refs/heads/t/sqrt'
[paraslash.git] / mood.c
diff --git a/mood.c b/mood.c
index c24b3d8b9da25c011e237b40e4508b0b61894598..bbe3a8ae08c65748c1414b6f16fe91bda669b32e 100644 (file)
--- a/mood.c
+++ b/mood.c
 #include "afh.h"
 #include "afs.h"
 #include "list.h"
-#include "ipc.h"
 #include "mm.h"
-#include "sideband.h"
 #include "mood.h"
-#include "sched.h"
 
 /**
  * Contains statistical data of the currently admissible audio files.
@@ -121,27 +118,23 @@ __a_const static uint32_t fls64(uint64_t v)
 }
 
 /*
- * Rough approximation to sqrt.
+ * Compute the integer square root floor(sqrt(x)).
  *
- * It returns an integer res with res * res <= x. Taken 2007 from the linux
- * source tree.
+ * Taken 2007 from the linux source tree.
  */
 __a_const static uint64_t int_sqrt(uint64_t x)
 {
-       uint64_t op, res, one = 1;
-       op = x;
-       res = 0;
+       uint64_t op = x, res = 0, one = 1;
 
        one = one << (fls64(x) & ~one);
        while (one != 0) {
                if (op >= res + one) {
                        op = op - (res + one);
-                       res = res +  2 * one;
+                       res = res + 2 * one;
                }
                res /= 2;
                one /= 4;
        }
-//     PARA_NOTICE_LOG("sqrt(%llu) = %llu\n", x, res);
        return res;
 }
 
@@ -395,9 +388,7 @@ success:
        ret = 1;
 out:
        free_argv(argv);
-       if (ret >= 0)
-               return ret;
-       if (mi) {
+       if (mi && (ret < 0 || !mlpd->m)) { /* mi was not added to any list */
                free(mi->parser_data);
                free(mi);
        }