Skip to content

Commit fbdb597

Browse files
MaxKellermanntridge
authored andcommitted
make lots of global variables const
This way, they can live in `.rodata` and the compiler is allowed to do certain optimizations.
1 parent 1c5ebdc commit fbdb597

File tree

10 files changed

+17
-17
lines changed

10 files changed

+17
-17
lines changed

batch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static int *flag_ptr[] = {
7575
NULL
7676
};
7777

78-
static char *flag_name[] = {
78+
static const char *const flag_name[] = {
7979
"--recurse (-r)",
8080
"--owner (-o)",
8181
"--group (-g)",

daemon-parm.awk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
BEGIN {
77
heading = "/* DO NOT EDIT THIS FILE! It is auto-generated from a list of values in " ARGV[1] "! */\n\n"
88
sect = psect = defines = accessors = prior_ptype = ""
9-
parms = "\nstatic struct parm_struct parm_table[] = {"
9+
parms = "\nstatic const struct parm_struct parm_table[] = {"
1010
comment_fmt = "\n/********** %s **********/\n"
1111
tdstruct = "typedef struct {"
1212
}

flist.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3167,8 +3167,8 @@ static void output_flist(struct file_list *flist)
31673167
} else
31683168
*uidbuf = '\0';
31693169
if (gid_ndx) {
3170-
static char parens[] = "(\0)\0\0\0";
3171-
char *pp = parens + (file->flags & FLAG_SKIP_GROUP ? 0 : 3);
3170+
static const char parens[] = "(\0)\0\0\0";
3171+
const char *pp = parens + (file->flags & FLAG_SKIP_GROUP ? 0 : 3);
31723172
snprintf(gidbuf, sizeof gidbuf, " gid=%s%u%s",
31733173
pp, F_GROUP(file), pp + 2);
31743174
} else

io.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static int active_filecnt = 0;
117117
static OFF_T active_bytecnt = 0;
118118
static int first_message = 1;
119119

120-
static char int_byte_extra[64] = {
120+
static const char int_byte_extra[64] = {
121121
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* (00 - 3F)/4 */
122122
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* (40 - 7F)/4 */
123123
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* (80 - BF)/4 */
@@ -1158,7 +1158,7 @@ void set_io_timeout(int secs)
11581158

11591159
static void check_for_d_option_error(const char *msg)
11601160
{
1161-
static char rsync263_opts[] = "BCDHIKLPRSTWabceghlnopqrtuvxz";
1161+
static const char rsync263_opts[] = "BCDHIKLPRSTWabceghlnopqrtuvxz";
11621162
char *colon;
11631163
int saw_d = 0;
11641164

lib/md5.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ void md5_update(md_context *ctx, const uchar *input, uint32 length)
197197
memcpy(ctx->buffer + left, input, length);
198198
}
199199

200-
static uchar md5_padding[CSUM_CHUNK] = { 0x80 };
200+
static const uchar md5_padding[CSUM_CHUNK] = { 0x80 };
201201

202202
void md5_result(md_context *ctx, uchar digest[MD5_DIGEST_LEN])
203203
{

loadparm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ typedef enum {
6565

6666
struct enum_list {
6767
int value;
68-
char *name;
68+
const char *name;
6969
};
7070

7171
struct parm_struct {
7272
char *label;
7373
parm_type type;
7474
parm_class class;
7575
void *ptr;
76-
struct enum_list *enum_list;
76+
const struct enum_list *enum_list;
7777
unsigned flags;
7878
};
7979

@@ -95,7 +95,7 @@ static item_list section_list = EMPTY_ITEM_LIST;
9595
static int iSectionIndex = -1;
9696
static BOOL bInGlobalSection = True;
9797

98-
static struct enum_list enum_syslog_facility[] = {
98+
static const struct enum_list enum_syslog_facility[] = {
9999
#ifdef LOG_AUTH
100100
{ LOG_AUTH, "auth" },
101101
#endif

main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ static void handle_stats(int f)
386386

387387
static void output_itemized_counts(const char *prefix, int *counts)
388388
{
389-
static char *labels[] = { "reg", "dir", "link", "dev", "special" };
389+
static char *const labels[] = { "reg", "dir", "link", "dev", "special" };
390390
char buf[1024], *pre = " (";
391391
int j, len = 0;
392392
int total = counts[0];

options.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ char *iconv_opt =
225225

226226
struct chmod_mode_struct *chmod_modes = NULL;
227227

228-
static const char *debug_verbosity[] = {
228+
static const char *const debug_verbosity[] = {
229229
/*0*/ NULL,
230230
/*1*/ NULL,
231231
/*2*/ "BIND,CMD,CONNECT,DEL,DELTASUM,DUP,FILTER,FLIST,ICONV",
@@ -236,7 +236,7 @@ static const char *debug_verbosity[] = {
236236

237237
#define MAX_VERBOSITY ((int)(sizeof debug_verbosity / sizeof debug_verbosity[0]) - 1)
238238

239-
static const char *info_verbosity[1+MAX_VERBOSITY] = {
239+
static const char *const info_verbosity[1+MAX_VERBOSITY] = {
240240
/*0*/ "NONREG",
241241
/*1*/ "COPY,DEL,FLIST,MISC,NAME,STATS,SYMSAFE",
242242
/*2*/ "BACKUP,MISC2,MOUNT,NAME2,REMOVE,SKIP",
@@ -474,7 +474,7 @@ static void parse_output_words(struct output_struct *words, short *levels, const
474474
static void output_item_help(struct output_struct *words)
475475
{
476476
short *levels = words == info_words ? info_levels : debug_levels;
477-
const char **verbosity = words == info_words ? info_verbosity : debug_verbosity;
477+
const char *const*verbosity = words == info_words ? info_verbosity : debug_verbosity;
478478
char buf[128], *opt, *fmt = "%-10s %s\n";
479479
int j;
480480

@@ -844,7 +844,7 @@ static struct poptOption long_options[] = {
844844
{0,0,0,0, 0, 0, 0}
845845
};
846846

847-
static struct poptOption long_daemon_options[] = {
847+
static const struct poptOption long_daemon_options[] = {
848848
/* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
849849
{"address", 0, POPT_ARG_STRING, &bind_address, 0, 0, 0 },
850850
{"bwlimit", 0, POPT_ARG_INT, &daemon_bwlimit, 0, 0, 0 },

tls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static void list_file(const char *fname)
230230
mtimebuf, atimebuf, crtimebuf, fname, linkbuf);
231231
}
232232

233-
static struct poptOption long_options[] = {
233+
static const struct poptOption long_options[] = {
234234
/* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
235235
{"atimes", 'U', POPT_ARG_NONE, &display_atimes, 0, 0, 0},
236236
#ifdef SUPPORT_CRTIMES

wildtest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int empties_mod = 0;
4040
int empty_at_start = 0;
4141
int empty_at_end = 0;
4242

43-
static struct poptOption long_options[] = {
43+
static const struct poptOption long_options[] = {
4444
/* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
4545
{"iterations", 'i', POPT_ARG_NONE, &output_iterations, 0, 0, 0},
4646
{"empties", 'e', POPT_ARG_STRING, 0, 'e', 0, 0},

0 commit comments

Comments
 (0)