format: Reduce size of struct fmt_spec from 6 bytes to 4.
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 8 Mar 2021 05:55:01 +0000 (21:55 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 8 Mar 2021 05:55:01 +0000 (21:55 -0800)
src/data/format.c
src/data/format.h
src/data/psql-reader.c
src/data/settings.c
src/language/data-io/matrix-reader.c
src/language/stats/aggregate.c
src/language/stats/rank.c
src/language/utilities/output.c
src/output/pivot-table.c
src/ui/gui/var-type-dialog.c

index f658a94fd20b8b51b0f41e95f9d63c3d4eff5eb3..74ee0e2e2ab3379222868ddce40aa1bf4fc795d6 100644 (file)
@@ -1324,7 +1324,7 @@ get_fmt_desc (enum fmt_type type)
   return &formats[type];
 }
 
-const struct fmt_spec F_8_0 = {FMT_F, 8, 0};
-const struct fmt_spec F_8_2 = {FMT_F, 8, 2};
-const struct fmt_spec F_4_3 = {FMT_F, 4, 3};
-const struct fmt_spec F_5_1 = {FMT_F, 5, 1};
+const struct fmt_spec F_8_0 = { .type = FMT_F, .w = 8, .d = 0 };
+const struct fmt_spec F_8_2 = { .type = FMT_F, .w = 8, .d = 2 };
+const struct fmt_spec F_4_3 = { .type = FMT_F, .w = 4, .d = 3 };
+const struct fmt_spec F_5_1 = { .type = FMT_F, .w = 5, .d = 1 };
index 1cb7bc6b7feb027573c82c5468b951942d01b6b0..4cde16b17a0b1352356f6b522c602bc18150b70e 100644 (file)
@@ -75,8 +75,8 @@ enum ATTRIBUTE ((packed)) fmt_type
 struct fmt_spec
   {
     enum fmt_type type;                /* One of FMT_*. */
-    uint16_t w;                        /* Width. */
     uint8_t d;                 /* Number of decimal places. */
+    uint16_t w;                        /* Width. */
   };
 
 /* Maximum width of any numeric format. */
index f4c44a177f5b53dea84405aae9ae5b5f6b2663f2..6780138b08da038015f0022ef81b59e606a2e2ce 100644 (file)
@@ -372,7 +372,7 @@ psql_open_reader (struct psql_read_info *info, struct dictionary **dict)
   for (i = 0 ; i < n_fields ; ++i)
     {
       struct variable *var;
-      struct fmt_spec fmt = {FMT_F, 8, 2};
+      struct fmt_spec fmt = { .type = FMT_F, .w = 8, .d = 2 };
       Oid type = PQftype (qres, i);
       int width = 0;
       int length ;
index 1b48299446d777491fbf9fad5cc087204481bb22..bcedc4172469463954c73758bd124edf40703511 100644 (file)
@@ -105,7 +105,7 @@ static struct settings the_settings = {
   true,                         /* mprint */
   40,                           /* mxloops */
   64L * 1024 * 1024,            /* workspace */
-  {FMT_F, 8, 2},                /* default_format */
+  { .type = FMT_F, .w = 8, .d = 2 }, /* default_format */
   false,                        /* testing_mode */
   6,                            /* fuzzbits */
   ENHANCED,                     /* cmd_algorithm */
index fbebb922fb5dab8e38a86483ba8b0f13e832355e..eac86744af9a5685e9715ad2625096be2418411a 100644 (file)
@@ -245,7 +245,7 @@ next_matrix_from_reader (struct matrix_material *mm,
       const union value *uvv  = case_data (c, mr->varname);
       int w = var_get_width (mr->varname);
 
-      struct fmt_spec fmt = {FMT_A, 0, 0};
+      struct fmt_spec fmt = { .type = FMT_A };
       fmt.w = w;
       char *vname = data_out (uvv, enc, &fmt, settings_get_fmt_settings ());
       struct substring the_name = ss_cstr (vname);
index 965e6e3903d420fc044f9d038671dab840ff03f8..9f0b271533888cc195c68637b9f569451d56e490 100644 (file)
@@ -93,24 +93,24 @@ struct agr_var
 /* Attributes of aggregation functions. */
 const struct agr_func agr_func_tab[] =
   {
-    {"SUM",     N_("Sum of values"),                         AGR_SV_YES, 0, -1,          {FMT_F, 8, 2}},
-    {"MEAN",   N_("Mean average"),                          AGR_SV_YES, 0, -1,          {FMT_F, 8, 2}},
-    {"MEDIAN", N_("Median average"),                        AGR_SV_YES, 0, -1,          {FMT_F, 8, 2}},
-    {"SD",      N_("Standard deviation"),                    AGR_SV_YES, 0, -1,          {FMT_F, 8, 2}},
+    {"SUM",     N_("Sum of values"),                         AGR_SV_YES, 0, -1,          { .type = FMT_F, .w = 8, .d = 2 }},
+    {"MEAN",   N_("Mean average"),                          AGR_SV_YES, 0, -1,          { .type = FMT_F, .w = 8, .d = 2 }},
+    {"MEDIAN", N_("Median average"),                        AGR_SV_YES, 0, -1,          { .type = FMT_F, .w = 8, .d = 2 }},
+    {"SD",      N_("Standard deviation"),                    AGR_SV_YES, 0, -1,          { .type = FMT_F, .w = 8, .d = 2 }},
     {"MAX",     N_("Maximum value"),                         AGR_SV_YES, 0, VAL_STRING,  {-1, -1, -1}},
     {"MIN",     N_("Minimum value"),                         AGR_SV_YES, 0, VAL_STRING,  {-1, -1, -1}},
-    {"PGT",     N_("Percentage greater than"),               AGR_SV_YES, 1, VAL_NUMERIC, {FMT_F, 5, 1}},
-    {"PLT",     N_("Percentage less than"),                  AGR_SV_YES, 1, VAL_NUMERIC, {FMT_F, 5, 1}},
-    {"PIN",     N_("Percentage included in range"),          AGR_SV_YES, 2, VAL_NUMERIC, {FMT_F, 5, 1}},
-    {"POUT",    N_("Percentage excluded from range"),        AGR_SV_YES, 2, VAL_NUMERIC, {FMT_F, 5, 1}},
-    {"FGT",     N_("Fraction greater than"),                 AGR_SV_YES, 1, VAL_NUMERIC, {FMT_F, 5, 3}},
-    {"FLT",     N_("Fraction less than"),                    AGR_SV_YES, 1, VAL_NUMERIC, {FMT_F, 5, 3}},
-    {"FIN",     N_("Fraction included in range"),            AGR_SV_YES, 2, VAL_NUMERIC, {FMT_F, 5, 3}},
-    {"FOUT",    N_("Fraction excluded from range"),          AGR_SV_YES, 2, VAL_NUMERIC, {FMT_F, 5, 3}},
-    {"N",       N_("Number of cases"),                       AGR_SV_NO,  0, VAL_NUMERIC, {FMT_F, 7, 0}},
-    {"NU",      N_("Number of cases (unweighted)"),          AGR_SV_OPT, 0, VAL_NUMERIC, {FMT_F, 7, 0}},
-    {"NMISS",   N_("Number of missing values"),              AGR_SV_YES, 0, VAL_NUMERIC, {FMT_F, 7, 0}},
-    {"NUMISS",  N_("Number of missing values (unweighted)"), AGR_SV_YES, 0, VAL_NUMERIC, {FMT_F, 7, 0}},
+    {"PGT",     N_("Percentage greater than"),               AGR_SV_YES, 1, VAL_NUMERIC, { .type = FMT_F, .w = 5, .d = 1 }},
+    {"PLT",     N_("Percentage less than"),                  AGR_SV_YES, 1, VAL_NUMERIC, { .type = FMT_F, .w = 5, .d = 1 }},
+    {"PIN",     N_("Percentage included in range"),          AGR_SV_YES, 2, VAL_NUMERIC, { .type = FMT_F, .w = 5, .d = 1 }},
+    {"POUT",    N_("Percentage excluded from range"),        AGR_SV_YES, 2, VAL_NUMERIC, { .type = FMT_F, .w = 5, .d = 1 }},
+    {"FGT",     N_("Fraction greater than"),                 AGR_SV_YES, 1, VAL_NUMERIC, { .type = FMT_F, .w = 5, .d = 3 }},
+    {"FLT",     N_("Fraction less than"),                    AGR_SV_YES, 1, VAL_NUMERIC, { .type = FMT_F, .w = 5, .d = 3 }},
+    {"FIN",     N_("Fraction included in range"),            AGR_SV_YES, 2, VAL_NUMERIC, { .type = FMT_F, .w = 5, .d = 3 }},
+    {"FOUT",    N_("Fraction excluded from range"),          AGR_SV_YES, 2, VAL_NUMERIC, { .type = FMT_F, .w = 5, .d = 3 }},
+    {"N",       N_("Number of cases"),                       AGR_SV_NO,  0, VAL_NUMERIC, { .type = FMT_F, .w = 7, .d = 0 }},
+    {"NU",      N_("Number of cases (unweighted)"),          AGR_SV_OPT, 0, VAL_NUMERIC, { .type = FMT_F, .w = 7, .d = 0 }},
+    {"NMISS",   N_("Number of missing values"),              AGR_SV_YES, 0, VAL_NUMERIC, { .type = FMT_F, .w = 7, .d = 0 }},
+    {"NUMISS",  N_("Number of missing values (unweighted)"), AGR_SV_YES, 0, VAL_NUMERIC, { .type = FMT_F, .w = 7, .d = 0 }},
     {"FIRST",   N_("First non-missing value"),               AGR_SV_YES, 0, VAL_STRING,  {-1, -1, -1}},
     {"LAST",    N_("Last non-missing value"),                AGR_SV_YES, 0, VAL_STRING,  {-1, -1, -1}},
     {NULL,      NULL,                                        AGR_SV_NO,  0, -1,          {-1, -1, -1}},
index 3d090b2bdca567e58f8902fdaffe7978a0b92bfc..64c44a1e1ca2a108540d07e5f3471c16690738d3 100644 (file)
@@ -91,14 +91,14 @@ enum rank_func
   };
 
 static const struct fmt_spec dest_format[n_RANK_FUNCS] = {
-  {FMT_F, 9, 3}, /* rank */
-  {FMT_F, 6, 4}, /* normal */
-  {FMT_F, 6, 2}, /* percent */
-  {FMT_F, 6, 4}, /* rfraction */
-  {FMT_F, 6, 4}, /* proportion */
-  {FMT_F, 6, 0}, /* n */
-  {FMT_F, 3, 0}, /* ntiles */
-  {FMT_F, 8, 4}  /* savage */
+  [RANK]       = { .type = FMT_F, .w = 9, .d = 3 },
+  [NORMAL]     = { .type = FMT_F, .w = 6, .d = 4 },
+  [PERCENT]    = { .type = FMT_F, .w = 6, .d = 2 },
+  [RFRACTION]  = { .type = FMT_F, .w = 6, .d = 4 },
+  [PROPORTION] = { .type = FMT_F, .w = 6, .d = 4 },
+  [N]          = { .type = FMT_F, .w = 6, .d = 0 },
+  [NTILES]     = { .type = FMT_F, .w = 3, .d = 0 },
+  [SAVAGE]     = { .type = FMT_F, .w = 8, .d = 4 }
 };
 
 static const char * const function_name[n_RANK_FUNCS] = {
index 2d7e811885916b0dfd0b397eafd2907ba150819e..f0dd016a829bfb2daa7e4c1049453d8c4964a622 100644 (file)
@@ -61,7 +61,7 @@ cmd_output (struct lexer *lexer, struct dataset *ds UNUSED)
       else if (lex_match_id (lexer, "TABLECELLS"))
        {
           string_set_clear (&rc_names);
-         struct fmt_spec fmt = { 0, 0, 0 };
+         struct fmt_spec fmt = { .type = 0 };
 
          while (lex_token (lexer) != T_SLASH &&
                 lex_token (lexer) != T_ENDCMD)
index af9a2e9479d1750053744a141328266e74a98fd9..f9082eb24e953a405f1b88e78a878e73d5a5e781 100644 (file)
@@ -748,11 +748,11 @@ struct result_class
 /* Formats for most of the result classes. */
 static struct result_class result_classes[] =
   {
-    { PIVOT_RC_INTEGER,      { FMT_F,   40, 0 } },
-    { PIVOT_RC_PERCENT,      { FMT_PCT, 40, 1 } },
-    { PIVOT_RC_CORRELATION,  { FMT_F,   40, 3 } },
-    { PIVOT_RC_SIGNIFICANCE, { FMT_F,   40, 3 } },
-    { PIVOT_RC_RESIDUAL,     { FMT_F,   40, 2 } },
+    { PIVOT_RC_INTEGER,      { .type = FMT_F,   .w = 40, .d = 0 } },
+    { PIVOT_RC_PERCENT,      { .type = FMT_PCT, .w = 40, .d = 1 } },
+    { PIVOT_RC_CORRELATION,  { .type = FMT_F,   .w = 40, .d = 3 } },
+    { PIVOT_RC_SIGNIFICANCE, { .type = FMT_F,   .w = 40, .d = 3 } },
+    { PIVOT_RC_RESIDUAL,     { .type = FMT_F,   .w = 40, .d = 2 } },
     { PIVOT_RC_COUNT,        { 0, 0, 0 } },
     { PIVOT_RC_OTHER,        { 0, 0, 0 } },
   };
index bc5f11904e0cd358b34efb464151d0b31430a86e..a6d89cbf8a38508f8a6ead99b4434f7454f4d4a1 100644 (file)
 
 static const struct fmt_spec date_format[] =
   {
-    {FMT_DATE,  11, 0},
-    {FMT_DATE,   9, 0},
-    {FMT_ADATE, 10, 0},
-    {FMT_ADATE, 8, 0},
-    {FMT_EDATE, 10, 0},
-    {FMT_EDATE, 8, 0},
-    {FMT_SDATE, 10, 0},
-    {FMT_SDATE, 8, 0},
-    {FMT_JDATE, 5, 0},
-    {FMT_JDATE, 7, 0},
-    {FMT_QYR, 8, 0},
-    {FMT_QYR, 6, 0},
-    {FMT_MOYR, 8, 0},
-    {FMT_MOYR, 6, 0},
-    {FMT_WKYR, 10, 0},
-    {FMT_WKYR, 8, 0},
-    {FMT_DATETIME, 17, 0},
-    {FMT_DATETIME, 20, 0},
-    {FMT_YMDHMS, 16, 0},
-    {FMT_YMDHMS, 20, 0}
+    { .type = FMT_DATE, .w = 11, .d = 0 },
+    { .type = FMT_DATE, .w = 9, .d = 0 },
+    { .type = FMT_ADATE, .w = 10, .d = 0 },
+    { .type = FMT_ADATE, .w = 8, .d = 0 },
+    { .type = FMT_EDATE, .w = 10, .d = 0 },
+    { .type = FMT_EDATE, .w = 8, .d = 0 },
+    { .type = FMT_SDATE, .w = 10, .d = 0 },
+    { .type = FMT_SDATE, .w = 8, .d = 0 },
+    { .type = FMT_JDATE, .w = 5, .d = 0 },
+    { .type = FMT_JDATE, .w = 7, .d = 0 },
+    { .type = FMT_QYR, .w = 8, .d = 0 },
+    { .type = FMT_QYR, .w = 6, .d = 0 },
+    { .type = FMT_MOYR, .w = 8, .d = 0 },
+    { .type = FMT_MOYR, .w = 6, .d = 0 },
+    { .type = FMT_WKYR, .w = 10, .d = 0 },
+    { .type = FMT_WKYR, .w = 8, .d = 0 },
+    { .type = FMT_DATETIME, .w = 17, .d = 0 },
+    { .type = FMT_DATETIME, .w = 20, .d = 0 },
+    { .type = FMT_YMDHMS, .w = 16, .d = 0 },
+    { .type = FMT_YMDHMS, .w = 20, .d = 0 }
   };
 
 
 static const struct fmt_spec dollar_format[] =
   {
-    {FMT_DOLLAR, 2, 0},
-    {FMT_DOLLAR, 3, 0},
-    {FMT_DOLLAR, 4, 0},
-    {FMT_DOLLAR, 7, 2},
-    {FMT_DOLLAR, 6, 0},
-    {FMT_DOLLAR, 9, 2},
-    {FMT_DOLLAR, 8, 0},
-    {FMT_DOLLAR, 11, 2},
-    {FMT_DOLLAR, 12, 0},
-    {FMT_DOLLAR, 15, 2},
-    {FMT_DOLLAR, 16, 0},
-    {FMT_DOLLAR, 19, 2}
+    { .type = FMT_DOLLAR, .w = 2, .d = 0 },
+    { .type = FMT_DOLLAR, .w = 3, .d = 0 },
+    { .type = FMT_DOLLAR, .w = 4, .d = 0 },
+    { .type = FMT_DOLLAR, .w = 7, .d = 2 },
+    { .type = FMT_DOLLAR, .w = 6, .d = 0 },
+    { .type = FMT_DOLLAR, .w = 9, .d = 2 },
+    { .type = FMT_DOLLAR, .w = 8, .d = 0 },
+    { .type = FMT_DOLLAR, .w = 11, .d = 2 },
+    { .type = FMT_DOLLAR, .w = 12, .d = 0 },
+    { .type = FMT_DOLLAR, .w = 15, .d = 2 },
+    { .type = FMT_DOLLAR, .w = 16, .d = 0 },
+    { .type = FMT_DOLLAR, .w = 19, .d = 2 }
   };
 
 static const int cc_format[] =