bepeephole: Inline be_peephole_new_node() into its only caller.
[libfirm] / ir / stat / distrib.c
index 4c92957..8c69332 100644 (file)
@@ -1,20 +1,6 @@
 /*
- * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
- *
  * This file is part of libFirm.
- *
- * This file may be distributed and/or modified under the terms of the
- * GNU General Public License version 2 as published by the Free Software
- * Foundation and appearing in the file LICENSE.GPL included in the
- * packaging of this file.
- *
- * Licensees holding valid libFirm Professional Edition licenses may use
- * this file in accordance with the libFirm Commercial License.
- * Agreement provided with the Software.
- *
- * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
- * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE.
+ * Copyright (C) 2012 University of Karlsruhe.
  */
 
 /**
@@ -186,10 +172,9 @@ void stat_insert_int_distrib_tbl(distrib_tbl_t *tbl, int key)
  */
 int stat_get_count_distrib_tbl(distrib_tbl_t *tbl)
 {
-       distrib_entry_t *entry;
        counter_t cnt = ZERO_CNT;
 
-       foreach_pset(tbl->hash_map, distrib_entry_t*, entry)
+       foreach_pset(tbl->hash_map, distrib_entry_t, entry)
                cnt_add(&cnt, &entry->cnt);
        return cnt_to_uint(&cnt);
 }
@@ -199,26 +184,19 @@ int stat_get_count_distrib_tbl(distrib_tbl_t *tbl)
  */
 double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl)
 {
-       distrib_entry_t *entry;
        size_t count;
        double sum;
 
        if (tbl->int_dist) {
                /* integer distribution, need min, max */
-               int min, max;
-
-               entry = (distrib_entry_t*)pset_first(tbl->hash_map);
-
-               if (! entry)
+               if (pset_count(tbl->hash_map) == 0)
                        return 0.0;
 
-               min =
-               max = PTR_TO_INT(entry->object);
-               sum = cnt_to_dbl(&entry->cnt);
-
+               int min = INT_MAX;
+               int max = INT_MIN;
+               sum = 0.0;
 
-               for (entry = (distrib_entry_t*)pset_next(tbl->hash_map); entry != NULL;
-                    entry = (distrib_entry_t*)pset_next(tbl->hash_map)) {
+               foreach_pset(tbl->hash_map, distrib_entry_t, entry) {
                        int value = PTR_TO_INT(entry->object);
 
                        if (value < min)
@@ -232,7 +210,7 @@ double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl)
        } else {
                sum = 0.0;
                count = 0;
-               foreach_pset(tbl->hash_map, distrib_entry_t*, entry) {
+               foreach_pset(tbl->hash_map, distrib_entry_t, entry) {
                        sum += cnt_to_dbl(&entry->cnt);
                        ++count;
                }
@@ -246,20 +224,19 @@ double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl)
  */
 double stat_calc_avg_distrib_tbl(distrib_tbl_t *tbl)
 {
-       distrib_entry_t *entry;
-       size_t          count = 0;
-       double          sum   = 0.0;
+       size_t count = 0;
+       double sum   = 0.0;
 
        if (tbl->int_dist) {
                if (pset_count(tbl->hash_map) <= 0)
                        return 0.0;
 
-               foreach_pset(tbl->hash_map, distrib_entry_t*, entry) {
+               foreach_pset(tbl->hash_map, distrib_entry_t, entry) {
                        sum   += cnt_to_dbl(&entry->cnt) * PTR_TO_INT(entry->object);
                        count += cnt_to_uint(&entry->cnt);
                }
        } else {
-               foreach_pset(tbl->hash_map, distrib_entry_t*, entry) {
+               foreach_pset(tbl->hash_map, distrib_entry_t, entry) {
                        sum += cnt_to_dbl(&entry->cnt);
                        ++count;
                }
@@ -273,8 +250,6 @@ double stat_calc_avg_distrib_tbl(distrib_tbl_t *tbl)
  */
 void stat_iterate_distrib_tbl(const distrib_tbl_t *tbl, eval_distrib_entry_fun eval, void *env)
 {
-       distrib_entry_t *entry;
-
-       foreach_pset(tbl->hash_map, distrib_entry_t*, entry)
+       foreach_pset(tbl->hash_map, distrib_entry_t, entry)
                eval(entry, env);
 }