From: Ben Pfaff Date: Mon, 8 Mar 2021 05:39:19 +0000 (-0800) Subject: format: Reduce size of struct fmt_spec from 12 bytes to 6. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da67dbb8a63ee516a6ae69c6099fde077dc20dcc;p=pspp format: Reduce size of struct fmt_spec from 12 bytes to 6. --- diff --git a/src/data/format.c b/src/data/format.c index a4c52b788e..f658a94fd2 100644 --- a/src/data/format.c +++ b/src/data/format.c @@ -184,10 +184,7 @@ fmt_settings_set_cc (struct fmt_settings *settings, enum fmt_type type, struct fmt_spec fmt_for_input (enum fmt_type type, int w, int d) { - struct fmt_spec f; - f.type = type; - f.w = w; - f.d = d; + struct fmt_spec f = { .type = type, .w = w, .d = d }; assert (fmt_check_input (&f)); return f; } @@ -197,10 +194,7 @@ fmt_for_input (enum fmt_type type, int w, int d) struct fmt_spec fmt_for_output (enum fmt_type type, int w, int d) { - struct fmt_spec f; - f.type = type; - f.w = w; - f.d = d; + struct fmt_spec f = { .type = type, .w = w, .d = d }; assert (fmt_check_output (&f)); return f; } @@ -1144,12 +1138,8 @@ fmt_clamp_width (struct fmt_spec *fmt, enum fmt_use use) static void fmt_clamp_decimals (struct fmt_spec *fmt, enum fmt_use use) { - int max_d; - - max_d = fmt_max_decimals (fmt->type, fmt->w, use); - if (fmt->d < 0) - fmt->d = 0; - else if (fmt->d > max_d) + int max_d = fmt_max_decimals (fmt->type, fmt->w, use); + if (fmt->d > max_d) fmt->d = max_d; } diff --git a/src/data/format.h b/src/data/format.h index 21b75a14f5..1cb7bc6b7f 100644 --- a/src/data/format.h +++ b/src/data/format.h @@ -56,7 +56,7 @@ enum fmt_category }; /* Format type. */ -enum fmt_type +enum ATTRIBUTE ((packed)) fmt_type { #define FMT(NAME, METHOD, IMIN, OMIN, IO, CATEGORY) FMT_##NAME, #include "format.def" @@ -75,8 +75,8 @@ enum fmt_type struct fmt_spec { enum fmt_type type; /* One of FMT_*. */ - int w; /* Width. */ - int d; /* Number of decimal places. */ + uint16_t w; /* Width. */ + uint8_t d; /* Number of decimal places. */ }; /* Maximum width of any numeric format. */ diff --git a/src/language/data-io/get-data.c b/src/language/data-io/get-data.c index cdc8674005..af44f03a2a 100644 --- a/src/language/data-io/get-data.c +++ b/src/language/data-io/get-data.c @@ -626,7 +626,8 @@ parse_get_txt (struct lexer *lexer, struct dataset *ds) { char fmt_type_name[FMT_TYPE_LEN_MAX + 1]; enum fmt_type fmt_type; - int w, d; + uint16_t w; + uint8_t d; if (!parse_column_range (lexer, 0, &fc, &lc, NULL)) goto error; diff --git a/src/language/lexer/format-parser.c b/src/language/lexer/format-parser.c index 2c05335ff9..2ecd539b8f 100644 --- a/src/language/lexer/format-parser.c +++ b/src/language/lexer/format-parser.c @@ -34,7 +34,7 @@ static bool parse_abstract_format_specifier__ (struct lexer *lexer, char type[FMT_TYPE_LEN_MAX + 1], - int *width, int *decimals) + uint16_t *width, uint8_t *decimals) { struct substring s; struct substring type_ss, width_ss, decimals_ss; @@ -90,7 +90,7 @@ error: bool parse_abstract_format_specifier (struct lexer *lexer, char type[FMT_TYPE_LEN_MAX + 1], - int *width, int *decimals) + uint16_t *width, uint8_t *decimals) { bool ok = parse_abstract_format_specifier__ (lexer, type, width, decimals); if (ok) diff --git a/src/language/lexer/format-parser.h b/src/language/lexer/format-parser.h index ae1f545dbf..8704e93c47 100644 --- a/src/language/lexer/format-parser.h +++ b/src/language/lexer/format-parser.h @@ -22,7 +22,7 @@ struct lexer; bool parse_abstract_format_specifier (struct lexer *, char *type, - int *width, int *decimals); + uint16_t *width, uint8_t *decimals); enum fmt_type ; struct fmt_spec; diff --git a/src/language/stats/autorecode.c b/src/language/stats/autorecode.c index cd1a220aff..005ba7622a 100644 --- a/src/language/stats/autorecode.c +++ b/src/language/stats/autorecode.c @@ -387,7 +387,7 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds) old_values->root, pivot_value_new_value ( &item->from, item->width, (item->width - ? &(struct fmt_spec) { FMT_F, item->width, 0 } + ? &(struct fmt_spec) { .type = FMT_F, .w = item->width } : &spec->format), dict_get_encoding (dict))); pivot_table_put2 (table, 0, old_value_idx, diff --git a/src/language/utilities/output.c b/src/language/utilities/output.c index 567314eb6c..2d7e811885 100644 --- a/src/language/utilities/output.c +++ b/src/language/utilities/output.c @@ -86,8 +86,8 @@ cmd_output (struct lexer *lexer, struct dataset *ds UNUSED) else if (lex_match_id (lexer, "FORMAT")) { char type[FMT_TYPE_LEN_MAX + 1]; - int width = -1; - int decimals = -1; + uint16_t width; + uint8_t decimals; if (! lex_force_match (lexer, T_EQUALS)) goto error; diff --git a/src/output/pivot-table.c b/src/output/pivot-table.c index 55559773c8..af9a2e9479 100644 --- a/src/output/pivot-table.c +++ b/src/output/pivot-table.c @@ -869,7 +869,7 @@ pivot_table_create__ (struct pivot_value *title, const char *subtype) table->ref_cnt = 1; table->show_title = true; table->show_caption = true; - table->weight_format = (struct fmt_spec) { FMT_F, 40, 0 }; + table->weight_format = (struct fmt_spec) { .type = FMT_F, .w = 40 }; table->title = title; table->subtype = subtype ? pivot_value_new_text (subtype) : NULL; table->command_c = xstrdup_if_nonempty (output_get_command_name ()); @@ -2795,7 +2795,7 @@ struct pivot_value * pivot_value_new_integer (double x) { struct pivot_value *value = pivot_value_new_number (x); - value->numeric.format = (struct fmt_spec) { FMT_F, 40, 0 }; + value->numeric.format = (struct fmt_spec) { .type = FMT_F, .w = 40 }; return value; } diff --git a/src/output/spv/spv-legacy-decoder.c b/src/output/spv/spv-legacy-decoder.c index 7641d78ed0..d8ddb82e31 100644 --- a/src/output/spv/spv-legacy-decoder.c +++ b/src/output/spv/spv-legacy-decoder.c @@ -277,7 +277,7 @@ spv_series_parse_value_map_entry (struct hmap *map, vme->from); char *error = spv_map_insert (map, from, vme->to, true, - &(struct fmt_spec) { FMT_A, 40, 0 }); + &(struct fmt_spec) { .type = FMT_A, .w = 40 }); if (error) return error; @@ -367,7 +367,7 @@ decode_number_format (const struct spvdx_number_format *nf) if (d < 0 || d > 15) d = 2; - struct fmt_spec f = (struct fmt_spec) { type, 40, d }; + struct fmt_spec f = (struct fmt_spec) { .type = type, .w = 40, .d = d }; fmt_fix_output (&f); return f; } diff --git a/src/output/spv/spv-writer.c b/src/output/spv/spv-writer.c index 549a0d8f84..2e24a33e9b 100644 --- a/src/output/spv/spv-writer.c +++ b/src/output/spv/spv-writer.c @@ -644,9 +644,10 @@ put_value (struct buf *buf, const struct pivot_value *value) put_value_mod (buf, value, NULL); size_t len = strlen (value->string.s); if (value->string.hex) - put_format (buf, &(struct fmt_spec) { FMT_AHEX, len * 2, 0 }, false); + put_format (buf, &(struct fmt_spec) { .type = FMT_AHEX, .w = len * 2 }, + false); else - put_format (buf, &(struct fmt_spec) { FMT_A, len, 0 }, false); + put_format (buf, &(struct fmt_spec) { .type = FMT_A, .w = len }, false); put_string (buf, value->string.value_label); put_string (buf, value->string.var_name); put_show_values (buf, value->string.show);