Permalink
Browse files

Declare many structures const (closes #3552)

Many structs used in mutt are actually constant but are defined
without the 'const' keyword. This can slow initialization (slightly)
in some environments due to extra copying and increases the amount of
writable RAM required at run-time, which can be significant on non-MMU
systems. Using const can also increase the opportunities for compiler
optimization.

The attached patch marks many such structures as const. On my test x86
build, this reduces the size of .data by over 50%.

--HG--
branch : HEAD
  • Loading branch information...
1 parent c64e447 commit 9689735c55503946e5f452c47385f005c55a7421 @dfandrich dfandrich committed Dec 3, 2011
Showing with 122 additions and 121 deletions.
  1. +1 −1 addrbook.c
  2. +1 −1 browser.c
  3. +3 −3 charset.c
  4. +3 −3 color.c
  5. +2 −2 compose.c
  6. +2 −2 crypt-gpgme.c
  7. +2 −2 curs_lib.c
  8. +1 −1 curs_main.c
  9. +2 −2 date.c
  10. +1 −1 enter.c
  11. +13 −13 functions.h
  12. +6 −6 globals.h
  13. +3 −3 handler.c
  14. +7 −7 help.c
  15. +2 −2 imap/auth.c
  16. +1 −1 imap/command.c
  17. +1 −1 imap/message.c
  18. +2 −2 imap/utf7.c
  19. +2 −1 imap/util.c
  20. +9 −8 init.c
  21. +1 −1 init.h
  22. +12 −12 keymap.c
  23. +15 −16 keymap.h
  24. +3 −3 lib.c
  25. +3 −3 mapping.h
  26. +3 −3 mime.h
  27. +1 −1 mutt_ssl.c
  28. +2 −2 pager.c
  29. +1 −1 parse.c
  30. +3 −3 pattern.c
  31. +1 −1 pgpkey.c
  32. +1 −1 pgpmicalg.c
  33. +2 −2 pop_auth.c
  34. +1 −1 postpone.c
  35. +1 −1 protos.h
  36. +1 −1 query.c
  37. +1 −1 recvattach.c
  38. +1 −1 remailer.c
  39. +1 −1 rfc2047.c
  40. +1 −1 rfc822.c
  41. +1 −1 rfc822.h
  42. +1 −1 sendlib.c
  43. +1 −1 url.c
View
@@ -33,7 +33,7 @@
#define RSORT(x) (SortAlias & SORT_REVERSE) ? -x : x
-static struct mapping_t AliasHelp[] = {
+static const struct mapping_t AliasHelp[] = {
{ N_("Exit"), OP_EXIT },
{ N_("Del"), OP_DELETE },
{ N_("Undel"), OP_UNDELETE },
View
@@ -42,7 +42,7 @@
#include <errno.h>
#include <locale.h>
-static struct mapping_t FolderHelp[] = {
+static const struct mapping_t FolderHelp[] = {
{ N_("Exit"), OP_EXIT },
{ N_("Chdir"), OP_CHANGE_DIRECTORY },
{ N_("Mask"), OP_ENTER_MASK },
View
@@ -50,10 +50,10 @@
* a preferred MIME name is given.
*/
-static struct
+static const const struct
{
- char *key;
- char *pref;
+ const char *key;
+ const char *pref;
}
PreferredMIMENames[] =
{
View
@@ -55,7 +55,7 @@ typedef struct color_list
static COLOR_LIST *ColorList = NULL;
static int UserColors = 0;
-static struct mapping_t Colors[] =
+static const struct mapping_t Colors[] =
{
{ "black", COLOR_BLACK },
{ "blue", COLOR_BLUE },
@@ -73,7 +73,7 @@ static struct mapping_t Colors[] =
#endif /* HAVE_COLOR */
-static struct mapping_t Fields[] =
+static const struct mapping_t Fields[] =
{
{ "hdrdefault", MT_COLOR_HDEFAULT },
{ "quoted", MT_COLOR_QUOTED },
@@ -159,7 +159,7 @@ void ci_start_color (void)
#ifdef USE_SLANG_CURSES
static char *get_color_name (char *dest, size_t destlen, int val)
{
- static char * missing[3] = {"brown", "lightgray", "default"};
+ static const char * const missing[3] = {"brown", "lightgray", "default"};
int i;
switch (val)
View
@@ -74,7 +74,7 @@ enum
#define TITLE_FMT "%10s" /* Used for Prompts, which are ASCII */
#define W (COLS - HDR_XOFFSET)
-static char *Prompts[] =
+static const char * const Prompts[] =
{
"From: ",
"To: ",
@@ -85,7 +85,7 @@ static char *Prompts[] =
"Fcc: "
};
-static struct mapping_t ComposeHelp[] = {
+static const struct mapping_t ComposeHelp[] = {
{ N_("Send"), OP_COMPOSE_SEND_MESSAGE },
{ N_("Abort"), OP_EXIT },
{ "To", OP_COMPOSE_EDIT_TO },
View
@@ -129,7 +129,7 @@ static char *current_sender = NULL;
* General helper functions.
*/
-/* return true when S pints to a didgit or letter. */
+/* return true when s points to a digit or letter. */
static int
digit_or_letter (const unsigned char *s)
{
@@ -2923,7 +2923,7 @@ print_dn_part (FILE *fp, struct dn_array_s *dn, const char *key)
static void
print_dn_parts (FILE *fp, struct dn_array_s *dn)
{
- const char *stdpart[] = {
+ static const char * const stdpart[] = {
"CN", "OU", "O", "STREET", "L", "ST", "C", NULL
};
int any=0, any2=0, i;
View
@@ -129,7 +129,7 @@ event_t mutt_getch (void)
return (ch == ctrl ('G') ? err : ret);
}
-int _mutt_get_field (/* const */ char *field, char *buf, size_t buflen, int complete, int multiple, char ***files, int *numfiles)
+int _mutt_get_field (const char *field, char *buf, size_t buflen, int complete, int multiple, char ***files, int *numfiles)
{
int ret;
int x, y;
@@ -139,7 +139,7 @@ int _mutt_get_field (/* const */ char *field, char *buf, size_t buflen, int comp
do
{
CLEARLINE (LINES-1);
- addstr (field);
+ addstr ((char *)field); /* cast to get around bad prototypes */
mutt_refresh ();
getyx (stdscr, y, x);
ret = _mutt_enter_string (buf, buflen, y, x, complete, multiple, files, numfiles, es);
View
@@ -401,7 +401,7 @@ static void resort_index (MUTTMENU *menu)
menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
}
-static struct mapping_t IndexHelp[] = {
+static const struct mapping_t IndexHelp[] = {
{ N_("Quit"), OP_QUIT },
{ N_("Del"), OP_DELETE },
{ N_("Undel"), OP_UNDELETE },
View
@@ -69,7 +69,7 @@ time_t mutt_mktime (struct tm *t, int local)
{
time_t g;
- static int AccumDaysPerMonth[12] = {
+ static const int AccumDaysPerMonth[12] = {
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
};
@@ -118,7 +118,7 @@ static int isLeapYearFeb (struct tm *tm)
void mutt_normalize_time (struct tm *tm)
{
- static char DaysPerMonth[12] = {
+ static const char DaysPerMonth[12] = {
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
int nLeap;
View
@@ -191,7 +191,7 @@ static void replace_part (ENTER_STATE *state, size_t from, char *buf)
*/
static inline int is_shell_char(wchar_t ch)
{
- static wchar_t shell_chars[] = L"<>&()$?*;{}| "; /* ! not included because it can be part of a pathname in Mutt */
+ static const wchar_t shell_chars[] = L"<>&()$?*;{}| "; /* ! not included because it can be part of a pathname in Mutt */
return wcschr(shell_chars, ch) != NULL;
}
View
@@ -38,7 +38,7 @@
# include "doc/makedoc-defs.h"
#endif
-struct binding_t OpGeneric[] = { /* map: generic */
+const struct binding_t OpGeneric[] = { /* map: generic */
/*
** <para>
** The <emphasis>generic</emphasis> menu is not a real menu, but specifies common functions
@@ -82,7 +82,7 @@ struct binding_t OpGeneric[] = { /* map: generic */
{ NULL, 0, NULL }
};
-struct binding_t OpMain[] = { /* map: index */
+const struct binding_t OpMain[] = { /* map: index */
{ "create-alias", OP_CREATE_ALIAS, "a" },
{ "bounce-message", OP_BOUNCE_MESSAGE, "b" },
{ "break-thread", OP_MAIN_BREAK_THREAD, "#" },
@@ -172,7 +172,7 @@ struct binding_t OpMain[] = { /* map: index */
{ NULL, 0, NULL }
};
-struct binding_t OpPager[] = { /* map: pager */
+const struct binding_t OpPager[] = { /* map: pager */
{ "break-thread", OP_MAIN_BREAK_THREAD, "#" },
{ "create-alias", OP_CREATE_ALIAS, "a" },
{ "bounce-message", OP_BOUNCE_MESSAGE, "b" },
@@ -275,7 +275,7 @@ struct binding_t OpPager[] = { /* map: pager */
{ NULL, 0, NULL }
};
-struct binding_t OpAttach[] = { /* map: attachment */
+const struct binding_t OpAttach[] = { /* map: attachment */
{ "bounce-message", OP_BOUNCE_MESSAGE, "b" },
{ "display-toggle-weed", OP_DISPLAY_HEADERS, "h" },
{ "edit-type", OP_EDIT_TYPE, "\005" },
@@ -301,7 +301,7 @@ struct binding_t OpAttach[] = { /* map: attachment */
{ NULL, 0, NULL }
};
-struct binding_t OpCompose[] = { /* map: compose */
+const struct binding_t OpCompose[] = { /* map: compose */
{ "attach-file", OP_COMPOSE_ATTACH_FILE, "a" },
{ "attach-message", OP_COMPOSE_ATTACH_MESSAGE, "A" },
{ "edit-bcc", OP_COMPOSE_EDIT_BCC, "b" },
@@ -351,21 +351,21 @@ struct binding_t OpCompose[] = { /* map: compose */
{ NULL, 0, NULL }
};
-struct binding_t OpPost[] = { /* map: postpone */
+const struct binding_t OpPost[] = { /* map: postpone */
{ "delete-entry", OP_DELETE, "d" },
{ "undelete-entry", OP_UNDELETE, "u" },
{ NULL, 0, NULL }
};
-struct binding_t OpAlias[] = { /* map: alias */
+const struct binding_t OpAlias[] = { /* map: alias */
{ "delete-entry", OP_DELETE, "d" },
{ "undelete-entry", OP_UNDELETE, "u" },
{ NULL, 0, NULL }
};
/* The file browser */
-struct binding_t OpBrowser[] = { /* map: browser */
+const struct binding_t OpBrowser[] = { /* map: browser */
{ "change-dir", OP_CHANGE_DIRECTORY, "c" },
{ "display-filename", OP_BROWSER_TELL, "@" },
{ "enter-mask", OP_ENTER_MASK, "m" },
@@ -388,15 +388,15 @@ struct binding_t OpBrowser[] = { /* map: browser */
};
/* External Query Menu */
-struct binding_t OpQuery[] = { /* map: query */
+const struct binding_t OpQuery[] = { /* map: query */
{ "create-alias", OP_CREATE_ALIAS, "a" },
{ "mail", OP_MAIL, "m" },
{ "query", OP_QUERY, "Q" },
{ "query-append", OP_QUERY_APPEND, "A" },
{ NULL, 0, NULL }
};
-struct binding_t OpEditor[] = { /* map: editor */
+const struct binding_t OpEditor[] = { /* map: editor */
{ "bol", OP_EDITOR_BOL, "\001" },
{ "backward-char", OP_EDITOR_BACKWARD_CHAR, "\002" },
{ "backward-word", OP_EDITOR_BACKWARD_WORD, "\033b"},
@@ -424,7 +424,7 @@ struct binding_t OpEditor[] = { /* map: editor */
-struct binding_t OpPgp[] = { /* map: pgp */
+const struct binding_t OpPgp[] = { /* map: pgp */
{ "verify-key", OP_VERIFY_KEY, "c" },
{ "view-name", OP_VIEW_ID, "%" },
{ NULL, 0, NULL }
@@ -434,7 +434,7 @@ struct binding_t OpPgp[] = { /* map: pgp */
/* When using the GPGME based backend we have some useful functions
for the SMIME menu. */
-struct binding_t OpSmime[] = { /* map: smime */
+const struct binding_t OpSmime[] = { /* map: smime */
#ifdef CRYPT_BACKEND_GPGME
{ "verify-key", OP_VERIFY_KEY, "c" },
{ "view-name", OP_VIEW_ID, "%" },
@@ -445,7 +445,7 @@ struct binding_t OpSmime[] = { /* map: smime */
#ifdef MIXMASTER
-struct binding_t OpMix[] = { /* map: mixmaster */
+const struct binding_t OpMix[] = { /* map: mixmaster */
{ "accept", OP_MIX_USE, M_ENTER_S },
{ "append", OP_MIX_APPEND, "a" },
{ "insert", OP_MIX_INSERT, "i" },
View
@@ -266,14 +266,14 @@ WHERE char *SmimeGetCertEmailCommand;
#ifdef MAIN_C
-const char *Weekdays[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
-const char *Months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "ERR" };
+const char * const Weekdays[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
+const char * const Months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "ERR" };
-const char *BodyTypes[] = { "x-unknown", "audio", "application", "image", "message", "model", "multipart", "text", "video" };
-const char *BodyEncodings[] = { "x-unknown", "7bit", "8bit", "quoted-printable", "base64", "binary", "x-uuencoded" };
+const char * const BodyTypes[] = { "x-unknown", "audio", "application", "image", "message", "model", "multipart", "text", "video" };
+const char * const BodyEncodings[] = { "x-unknown", "7bit", "8bit", "quoted-printable", "base64", "binary", "x-uuencoded" };
#else
-extern const char *Weekdays[];
-extern const char *Months[];
+extern const char * const Weekdays[];
+extern const char * const Months[];
#endif
#ifdef MAIN_C
View
@@ -43,7 +43,7 @@
typedef int (*handler_t) (BODY *, STATE *);
-int Index_hex[128] = {
+const int Index_hex[128] = {
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
@@ -54,7 +54,7 @@ int Index_hex[128] = {
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1
};
-int Index_64[128] = {
+const int Index_64[128] = {
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63,
@@ -434,7 +434,7 @@ enum { RICH_PARAM=0, RICH_BOLD, RICH_UNDERLINE, RICH_ITALIC, RICH_NOFILL,
RICH_INDENT, RICH_INDENT_RIGHT, RICH_EXCERPT, RICH_CENTER, RICH_FLUSHLEFT,
RICH_FLUSHRIGHT, RICH_COLOR, RICH_LAST_TAG };
-static struct {
+static const struct {
const wchar_t *tag_name;
int index;
} EnrichedTags[] = {
View
@@ -31,10 +31,10 @@
#include <ctype.h>
#include <string.h>
-static struct binding_t *help_lookupFunction (int op, int menu)
+static const struct binding_t *help_lookupFunction (int op, int menu)
{
int i;
- struct binding_t *map;
+ const struct binding_t *map;
if (menu != MENU_PAGER)
{
@@ -66,7 +66,7 @@ void mutt_make_help (char *d, size_t dlen, char *txt, int menu, int op)
}
char *
-mutt_compile_help (char *buf, size_t buflen, int menu, struct mapping_t *items)
+mutt_compile_help (char *buf, size_t buflen, int menu, const struct mapping_t *items)
{
int i;
size_t len;
@@ -282,7 +282,7 @@ static void format_line (FILE *f, int ismacro,
static void dump_menu (FILE *f, int menu)
{
struct keymap_t *map;
- struct binding_t *b;
+ const struct binding_t *b;
char buf[SHORT_STRING];
/* browse through the keymap table */
@@ -318,7 +318,7 @@ static int is_bound (struct keymap_t *map, int op)
}
static void dump_unbound (FILE *f,
- struct binding_t *funcs,
+ const struct binding_t *funcs,
struct keymap_t *map,
struct keymap_t *aux)
{
@@ -336,9 +336,9 @@ void mutt_help (int menu)
{
char t[_POSIX_PATH_MAX];
char buf[SHORT_STRING];
- char *desc;
+ const char *desc;
FILE *f;
- struct binding_t *funcs;
+ const struct binding_t *funcs;
mutt_mktemp (t, sizeof (t));
View
@@ -28,7 +28,7 @@
#include "imap_private.h"
#include "auth.h"
-static imap_auth_t imap_authenticators[] = {
+static const imap_auth_t imap_authenticators[] = {
#ifdef USE_SASL
{ imap_auth_sasl, NULL },
#else
@@ -50,7 +50,7 @@ static imap_auth_t imap_authenticators[] = {
* authentication method if specified, or any. */
int imap_authenticate (IMAP_DATA* idata)
{
- imap_auth_t* authenticator;
+ const imap_auth_t* authenticator;
char* methods;
char* method;
char* delim;
View
@@ -53,7 +53,7 @@ static void cmd_parse_myrights (IMAP_DATA* idata, const char* s);
static void cmd_parse_search (IMAP_DATA* idata, const char* s);
static void cmd_parse_status (IMAP_DATA* idata, char* s);
-static char *Capabilities[] = {
+static const char * const Capabilities[] = {
"IMAP4",
"IMAP4rev1",
"STATUS",
View
@@ -71,7 +71,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
int rc, mfhrc, oldmsgcount;
int fetchlast = 0;
int maxuid = 0;
- const char *want_headers = "DATE FROM SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL";
+ static const char * const want_headers = "DATE FROM SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL";
progress_t progress;
int retval = -1;
Oops, something went wrong.

0 comments on commit 9689735

Please sign in to comment.