From: Ben Pfaff Date: Mon, 8 Mar 2021 06:52:43 +0000 (-0800) Subject: pivot-table: Reduce size of struct pivot_value from 96 bytes to 80. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=478f1bffcdec0b01391b8297e2df1a1f6aa7d4cf;p=pspp pivot-table: Reduce size of struct pivot_value from 96 bytes to 80. --- diff --git a/src/data/settings.h b/src/data/settings.h index 39bac54430..1361bef374 100644 --- a/src/data/settings.h +++ b/src/data/settings.h @@ -21,6 +21,7 @@ #include #include "data/format.h" +#include "libpspp/compiler.h" #include "libpspp/float-format.h" #include "libpspp/integer-format.h" #include "libpspp/message.h" @@ -106,7 +107,7 @@ void settings_set_fuzzbits (int); /* Whether to show variable or value labels or the underlying value or variable name. */ -enum settings_value_show +enum ATTRIBUTE ((packed)) settings_value_show { /* Use higher-level default. In a pivot_value, the default is taken from the pivot_table. diff --git a/src/output/ascii.c b/src/output/ascii.c index cd5fcec64b..cdd93aa8e6 100644 --- a/src/output/ascii.c +++ b/src/output/ascii.c @@ -1033,8 +1033,8 @@ ascii_test_write (struct output_driver *driver, .underline = underline, }; const struct pivot_value value = { - .type = PIVOT_VALUE_TEXT, .text = { + .type = PIVOT_VALUE_TEXT, .local = CONST_CAST (char *, s), .c = CONST_CAST (char *, s), .id = CONST_CAST (char *, s), diff --git a/src/output/pivot-table.c b/src/output/pivot-table.c index f9082eb24e..ad146a58ba 100644 --- a/src/output/pivot-table.c +++ b/src/output/pivot-table.c @@ -2692,8 +2692,8 @@ pivot_value_new_user_text_nocopy (char *text) { struct pivot_value *value = xmalloc (sizeof *value); *value = (struct pivot_value) { - .type = PIVOT_VALUE_TEXT, .text = { + .type = PIVOT_VALUE_TEXT, .local = text, .c = text, .id = text, @@ -2735,8 +2735,8 @@ pivot_value_new_text (const char *text) struct pivot_value *value = xmalloc (sizeof *value); *value = (struct pivot_value) { - .type = PIVOT_VALUE_TEXT, .text = { + .type = PIVOT_VALUE_TEXT, .local = local, .c = c, .id = c, @@ -2762,8 +2762,8 @@ pivot_value_new_text_format (const char *format, ...) struct pivot_value *value = xmalloc (sizeof *value); *value = (struct pivot_value) { - .type = PIVOT_VALUE_TEXT, .text = { + .type = PIVOT_VALUE_TEXT, .local = local, .c = c, .id = xstrdup (c), @@ -2784,8 +2784,10 @@ pivot_value_new_number (double x) { struct pivot_value *value = xmalloc (sizeof *value); *value = (struct pivot_value) { - .type = PIVOT_VALUE_NUMERIC, - .numeric = { .x = x, }, + .numeric = { + .type = PIVOT_VALUE_NUMERIC, + .x = x + }, }; return value; } @@ -2863,8 +2865,8 @@ pivot_value_new_variable (const struct variable *variable) { struct pivot_value *value = xmalloc (sizeof *value); *value = (struct pivot_value) { - .type = PIVOT_VALUE_VARIABLE, .variable = { + .type = PIVOT_VALUE_VARIABLE, .var_name = xstrdup (var_get_name (variable)), .var_label = xstrdup_if_nonempty (var_get_label (variable)), }, diff --git a/src/output/pivot-table.h b/src/output/pivot-table.h index 2a5d8467f8..0d6e333b06 100644 --- a/src/output/pivot-table.h +++ b/src/output/pivot-table.h @@ -579,7 +579,7 @@ void pivot_table_dump (const struct pivot_table *, int indentation); /* pivot_value. */ -enum pivot_value_type +enum ATTRIBUTE ((packed)) pivot_value_type { PIVOT_VALUE_NUMERIC, /* A value of a numeric variable. */ PIVOT_VALUE_STRING, /* A value of a string variable. */ @@ -656,62 +656,75 @@ struct pivot_value size_t *footnote_indexes; size_t n_footnotes; - enum pivot_value_type type; union { + enum pivot_value_type type; + /* PIVOT_VALUE_NUMERIC. */ struct { - double x; /* The numeric value. */ + enum pivot_value_type type; + enum settings_value_show show; /* Show value or label or both? */ struct fmt_spec format; /* Format to display 'x'. */ + bool honor_small; /* Honor value of pivot table 'small'? */ + double x; /* The numeric value. */ char *var_name; /* May be NULL. */ char *value_label; /* May be NULL. */ - enum settings_value_show show; /* Show value or label or both? */ - bool honor_small; /* Honor value of pivot table 'small'? */ } numeric; /* PIVOT_VALUE_STRING. */ struct { - char *s; /* The string value. */ + enum pivot_value_type type; + enum settings_value_show show; /* Show value or label or both? */ bool hex; /* Display in hex? */ + char *s; /* The string value. */ char *var_name; /* May be NULL. */ char *value_label; /* May be NULL. */ - enum settings_value_show show; /* Show value or label or both? */ } string; /* PIVOT_VALUE_VARIABLE. */ struct { + enum pivot_value_type type; + enum settings_value_show show; /* Show name or label or both? */ char *var_name; char *var_label; /* May be NULL. */ - enum settings_value_show show; /* Show name or label or both? */ } variable; /* PIVOT_VALUE_TEXT. */ struct { + enum pivot_value_type type; + /* 'local', 'c', and 'id' must all be nonnull, but they are allowed to be the same pointer. */ + bool user_provided; char *local; /* Localized. */ char *c; /* English. */ char *id; /* Identifier. */ - bool user_provided; } text; /* PIVOT_VALUE_TEMPLATE. */ struct { + enum pivot_value_type type; + + /* Arguments. + + The odd ordering in this struct reduces the overall size + of struct pivot_value. */ + unsigned int n_args; + struct pivot_argument *args; + /* Both 'local' and 'id' must be nonnull, but they are allowed to be the same pointer. */ char *local; /* Localized. */ char *id; /* Identifier. */ - struct pivot_argument *args; - size_t n_args; } template; }; diff --git a/src/output/spv/spv.c b/src/output/spv/spv.c index 93f61b20bb..9b0fe17a21 100644 --- a/src/output/spv/spv.c +++ b/src/output/spv/spv.c @@ -285,8 +285,8 @@ decode_container_text (const struct spvsx_container_text *ct) struct pivot_value *value = xmalloc (sizeof *value); *value = (struct pivot_value) { .font_style = font_style, - .type = PIVOT_VALUE_TEXT, .text = { + .type = PIVOT_VALUE_TEXT, .local = text, .c = text, .id = text, diff --git a/src/output/table.c b/src/output/table.c index 442b765134..bf22d2da5a 100644 --- a/src/output/table.c +++ b/src/output/table.c @@ -504,8 +504,8 @@ table_get_cell (const struct table *t, int x, int y, struct table_cell *cell) = t->styles[(opt & TAB_STYLE_MASK) >> TAB_STYLE_SHIFT]; static const struct pivot_value empty_value = { - .type = PIVOT_VALUE_TEXT, .text = { + .type = PIVOT_VALUE_TEXT, .local = (char *) "", .c = (char *) "", .id = (char *) "", diff --git a/tests/output/pivot-table-test.c b/tests/output/pivot-table-test.c index bf275b20d6..98336b2563 100644 --- a/tests/output/pivot-table-test.c +++ b/tests/output/pivot-table-test.c @@ -677,8 +677,10 @@ read_value (struct lexer *lexer, const struct pivot_table *pt, { value = xmalloc (sizeof *value); *value = (struct pivot_value) { - .type = PIVOT_VALUE_STRING, - .string = { .s = xstrdup (lex_tokcstr (lexer)) }, + .string = { + .type = PIVOT_VALUE_STRING, + .s = xstrdup (lex_tokcstr (lexer)) + }, }; lex_get (lexer); } @@ -686,8 +688,10 @@ read_value (struct lexer *lexer, const struct pivot_table *pt, { value = xmalloc (sizeof *value); *value = (struct pivot_value) { - .type = PIVOT_VALUE_VARIABLE, - .variable = { .var_name = xstrdup (lex_tokcstr (lexer)) }, + .variable = { + .type = PIVOT_VALUE_VARIABLE, + .var_name = xstrdup (lex_tokcstr (lexer)) + }, }; lex_get (lexer); }