math: Avoid unneeded extra allocations for fixed-size data structures.
[pspp] / src / math / percentiles.c
index a387d3d4c270b1685984b6758e899f98f239a5f6..1b4ff136328ecdbe0ba9fb2cd1bff521519d5803 100644 (file)
 
 #include "gl/xalloc.h"
 
-#include "gettext.h"
-#define _(msgid) gettext (msgid)
-#define N_(msgid) msgid
-
 double
 percentile_calculate (const struct percentile *ptl, enum pc_alg alg)
 {
@@ -143,8 +139,6 @@ static void
 destroy (struct statistic *stat)
 {
   struct percentile *ptl = UP_CAST (stat, struct percentile, parent.parent);
-  struct order_stats *os = &ptl->parent;
-  free (os->k);
   free (ptl);
 }
 
@@ -152,7 +146,7 @@ destroy (struct statistic *stat)
 struct percentile *
 percentile_create (double p, double W)
 {
-  struct percentile *ptl = xzalloc (sizeof (*ptl));
+  struct percentile *ptl = XZALLOC (struct percentile);
   struct order_stats *os = &ptl->parent;
   struct statistic *stat = &os->parent;
 
@@ -163,7 +157,7 @@ percentile_create (double p, double W)
   ptl->w = W;
 
   os->n_k = 2;
-  os->k = xcalloc (2, sizeof (*os->k));
+  os->k = ptl->k;
   os->k[0].tc = W * p;
   os->k[1].tc = (W + 1.0) * p;