Skip to content

Commit b6da1fd

Browse files
committed
maint: Reduce struct padding
1 parent f5441fc commit b6da1fd

File tree

5 files changed

+48
-37
lines changed

5 files changed

+48
-37
lines changed

src/config_rmw.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ extern const char *expire_age_str;
3232

3333
typedef struct
3434
{
35-
char uid[10];
36-
st_waste *st_waste_folder_props_head;
37-
bool force_required;
38-
int expire_age;
35+
st_waste *st_waste_folder_props_head; // Pointer with high alignment requirements
36+
37+
int expire_age; // 4-byte alignment, placed next
38+
39+
bool force_required; // Minimal alignment, placed after the int
40+
char uid[10]; // Character array, lower alignment, placed last
3941
} st_config;
4042

43+
4144
void print_config(FILE * restrict stream);
4245

4346
void

src/main.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ struct st_loc
4646
const char *home_dir;
4747
const char *config_dir;
4848
const char *config_file;
49+
4950
const char *data_dir;
5051
const char *purge_time_file;
5152
const char *mrl_file;
52-
const st_dir *st_directory;
53+
54+
const st_dir *st_directory; // Pointer to another struct, placed at the end for clarity
5355
};
56+

src/parse_cli_options.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2525
/** CLI option switches for rmw. */
2626
typedef struct
2727
{
28-
bool want_restore;
2928
int want_purge;
29+
int force;
30+
31+
/*! Alternate configuration file given at the command line with -c */
32+
const char *alt_config_file;
33+
34+
bool want_restore;
3035
bool want_empty_trash;
3136
bool want_top_level_bypass;
3237
bool want_orphan_chk;
3338
bool want_selection_menu;
3439
bool want_undo;
3540
bool most_recent_list;
3641
bool want_dry_run;
37-
int force;
42+
3843
/*! list waste folder option */
3944
bool list;
40-
/*! Alternate configuration file given at the command line with -c */
41-
const char *alt_config_file;
4245
} rmw_options;
4346

4447

48+
4549
void init_rmw_options(rmw_options * options);
4650

4751
void

src/time_rmw.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
4242
*/
4343
typedef struct
4444
{
45-
char suffix_added_dup_exists[LEN_MAX_TIME_STR_SUFFIX];
45+
time_t now; // Largest member, placed first to avoid alignment padding issues.
46+
char deletion_date[LEN_MAX_DELETION_DATE]; // Grouped char arrays together.
4647
char t_fmt[LEN_MAX_DELETION_DATE];
47-
char deletion_date[LEN_MAX_DELETION_DATE];
48-
time_t now;
48+
char suffix_added_dup_exists[LEN_MAX_TIME_STR_SUFFIX];
4949
} st_time;
5050

51+
5152
void init_time_vars(st_time * st_time_var);
5253

5354
#endif

src/trashinfo.h

+25-25
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,23 @@ struct st_waste
4141
/** The parent directory, e.g. $HOME/.local/share/Trash */
4242
char *parent;
4343

44-
/*! The info directory (where .trashinfo files are written) will be appended to the parent directory */
44+
/** The info directory (where .trashinfo files are written) will be appended to the parent directory */
4545
char *info;
46-
int len_info;
4746

48-
/** Appended to the parent directory, where files are moved to when they are rmw'ed
49-
*/
47+
/** Appended to the parent directory, where files are moved to when they are rmw'ed */
5048
char *files;
51-
int len_files;
49+
50+
/** If a waste folder is at the top level, a relative path will be
51+
* used (per the Freedesktop trash spec). See
52+
* https://github.com/theimpossibleastronaut/rmw/issues/299 for more
53+
* info */
54+
char *media_root;
55+
56+
/** Points to the previous WASTE directory in the linked list */
57+
st_waste *prev_node;
58+
59+
/** Points to the next WASTE directory in the linked list */
60+
st_waste *next_node;
5261

5362
/** The device number of the filesystem on which the file resides. rmw does
5463
* not copy files from one filesystem to another, but rather only moves them.
@@ -57,53 +66,44 @@ struct st_waste
5766
*/
5867
dev_t dev_num;
5968

60-
/** set to <tt>true</tt> if the parent directory is on a removable device,
69+
int len_info;
70+
int len_files;
71+
72+
/** Set to <tt>true</tt> if the parent directory is on a removable device,
6173
* <tt>false</tt> otherwise.
6274
*/
6375
bool removable;
6476

65-
/*
66-
* If a waste folder is at the top level, a relative path will be
67-
* used (per the Freedesktop trash spec). See
68-
https://github.com/theimpossibleastronaut/rmw/issues/299 for more
69-
info */
70-
char *media_root;
71-
7277
bool is_btrfs;
73-
74-
/** Points to the previous WASTE directory in the linked list
75-
*/
76-
st_waste *prev_node;
77-
78-
/** Points to the next WASTE directory in the linked list
79-
*/
80-
st_waste *next_node;
8178
};
8279

80+
8381
/** Holds information about a file that was specified for rmw'ing
8482
*/
8583
typedef struct
8684
{
8785
/** The absolute path to the file, stored later in a .trashinfo file */
8886
char *real_path;
8987

90-
/** The basename of the target file, and used for the basename of it's corresponding
88+
/** The basename of the target file, and used for the basename of its corresponding
9189
* .trashinfo file */
9290
const char *base_name;
9391

92+
/** The device number of the filesystem on which the file resides */
93+
dev_t dev_num;
94+
9495
/** The destination file name. This may be different if a file of the same name already
95-
* exists in the WASTE folder */
96+
* exists in the WASTE folder */
9697
char waste_dest_name[PATH_MAX];
9798

98-
dev_t dev_num;
99-
10099
/** Is <tt>true</tt> if the file exists in the destination WASTE/files folder,
101100
* false otherwise. If it's a duplicate, a string based on the current time
102101
* will be appended to \ref dest_name
103102
*/
104103
bool is_duplicate;
105104
} rmw_target;
106105

106+
107107
extern const char *lit_info;
108108
extern const char *path_key;
109109
extern const char *deletion_date_key;

0 commit comments

Comments
 (0)