Break ctables_cell_insert__() from ctables_cell_add__()
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 15 Jan 2022 05:03:11 +0000 (21:03 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 2 Apr 2022 01:48:55 +0000 (18:48 -0700)
src/language/stats/ctables.c

index ca2cfd9b66d2b7e3d05141948019627ccee8adc5..2e0b51334f2aac778662163650a56a342e991236 100644 (file)
@@ -2206,11 +2206,10 @@ ctables_categories_total (const struct ctables_categories *c)
           : NULL);
 }
 
-static void
+static struct ctables_cell *
 ctables_cell_insert__ (struct ctables_table *t, const struct ccase *c,
                        size_t ix[PIVOT_N_AXES],
-                       const struct ctables_category *cats[PIVOT_N_AXES][10],
-                       double weight)
+                       const struct ctables_category *cats[PIVOT_N_AXES][10])
 {
   const struct ctables_nest *ss = &t->stacks[t->summary_axis].nests[ix[t->summary_axis]];
 
@@ -2254,7 +2253,7 @@ ctables_cell_insert__ (struct ctables_table *t, const struct ccase *c,
                 goto not_equal;
         }
 
-      goto summarize;
+      return cell;
 
     not_equal: ;
     }
@@ -2294,8 +2293,18 @@ ctables_cell_insert__ (struct ctables_table *t, const struct ccase *c,
   for (enum ctables_domain_type dt = 0; dt < N_CTDTS; dt++)
     cell->domains[dt] = ctables_domain_insert (t, cell, dt);
   hmap_insert (&t->cells, &cell->node, hash);
+  return cell;
+}
+
+static void
+ctables_cell_add__ (struct ctables_table *t, const struct ccase *c,
+                    size_t ix[PIVOT_N_AXES],
+                    const struct ctables_category *cats[PIVOT_N_AXES][10],
+                    double weight)
+{
+  struct ctables_cell *cell = ctables_cell_insert__ (t, c, ix, cats);
+  const struct ctables_nest *ss = &t->stacks[t->summary_axis].nests[ix[t->summary_axis]];
 
-summarize: ;
   const struct ctables_summary_spec_set *sss
     = (cell->total ? &ss->total_sss : &ss->cell_sss);
   for (size_t i = 0; i < sss->n; i++)
@@ -2328,7 +2337,7 @@ recurse_totals (struct ctables_table *t, const struct ccase *c,
             {
               const struct ctables_category *save = cats[a][i];
               cats[a][i] = total;
-              ctables_cell_insert__ (t, c, ix, cats, weight);
+              ctables_cell_add__ (t, c, ix, cats, weight);
               recurse_totals (t, c, ix, cats, weight, a, i + 1);
               cats[a][i] = save;
             }
@@ -2371,7 +2380,7 @@ ctables_cell_insert (struct ctables_table *t,
         }
     }
 
-  ctables_cell_insert__ (t, c, ix, cats, weight);
+  ctables_cell_add__ (t, c, ix, cats, weight);
 
   recurse_totals (t, c, ix, cats, weight, 0, 0);
 
@@ -2387,7 +2396,7 @@ ctables_cell_insert (struct ctables_table *t,
           if (save->subtotal)
             {
               cats[a][i] = save->subtotal;
-              ctables_cell_insert__ (t, c, ix, cats, weight);
+              ctables_cell_add__ (t, c, ix, cats, weight);
               cats[a][i] = save;
             }
         }