treewide: mark things static and const

Mark some structures, arrays static/const at various places.
In some cases this prevents unnecessary initialization
when a function is entered.

All in all, the text segments across all shared
libraries are reduced by about 2 KiB. However,
the total size increases by about 2 KiB as well.
This commit is contained in:
Barnabás Pőcze 2021-06-27 17:47:13 +02:00
parent 48dbb4da3c
commit f5d51162c4
54 changed files with 303 additions and 241 deletions

View file

@ -1098,7 +1098,7 @@ static int client_node_port_buffers(void *data,
return 0;
}
static struct pw_client_node_methods client_node_methods = {
static const struct pw_client_node_methods client_node_methods = {
PW_VERSION_CLIENT_NODE_METHODS,
.get_node = client_node_get_node,
.update = client_node_update,

View file

@ -1095,7 +1095,7 @@ static void client_node0_event(void *data, struct spa_event *event)
}
}
static struct pw_client_node0_methods client_node0_methods = {
static const struct pw_client_node0_methods client_node0_methods = {
PW_VERSION_CLIENT_NODE0_METHODS,
.done = client_node0_done,
.update = client_node0_update,
@ -1303,12 +1303,13 @@ static const struct pw_resource_events resource_events = {
static void convert_properties(struct pw_properties *properties)
{
struct {
static const struct {
const char *from, *to;
} props[] = {
{ "pipewire.autoconnect", PW_KEY_NODE_AUTOCONNECT, },
{ "pipewire.target.node", PW_KEY_NODE_TARGET, }
};
uint32_t i;
const char *str;

View file

@ -2015,7 +2015,7 @@ pw_protocol_native_registry_event_demarshal[PW_REGISTRY_EVENT_NUM] =
[PW_REGISTRY_EVENT_GLOBAL_REMOVE] = { &registry_demarshal_global_remove, 0, }
};
const struct pw_protocol_marshal pw_protocol_native_registry_marshal = {
static const struct pw_protocol_marshal pw_protocol_native_registry_marshal = {
PW_TYPE_INTERFACE_Registry,
PW_VERSION_REGISTRY,
0,
@ -2050,7 +2050,7 @@ pw_protocol_native_module_method_demarshal[PW_MODULE_METHOD_NUM] =
[PW_MODULE_METHOD_ADD_LISTENER] = { NULL, 0, },
};
const struct pw_protocol_marshal pw_protocol_native_module_marshal = {
static const struct pw_protocol_marshal pw_protocol_native_module_marshal = {
PW_TYPE_INTERFACE_Module,
PW_VERSION_MODULE,
0,
@ -2084,7 +2084,7 @@ pw_protocol_native_factory_method_demarshal[PW_FACTORY_METHOD_NUM] =
[PW_FACTORY_METHOD_ADD_LISTENER] = { NULL, 0, },
};
const struct pw_protocol_marshal pw_protocol_native_factory_marshal = {
static const struct pw_protocol_marshal pw_protocol_native_factory_marshal = {
PW_TYPE_INTERFACE_Factory,
PW_VERSION_FACTORY,
0,

View file

@ -1,5 +1,4 @@
const struct type_info {
static const struct type_info {
const char *type;
const char *name;
uint32_t id;

View file

@ -220,7 +220,7 @@ enum {
SOURCE_FLAT_VOLUME = 0x0080U,
};
static const char *port_types[] = {
static const char * const port_types[] = {
"unknown",
"aux",
"speaker",

View file

@ -380,7 +380,7 @@ bool channel_map_valid(const struct channel_map *map)
}
static const char *encoding_names[] = {
static const char * const encoding_names[] = {
[ENCODING_ANY] = "ANY",
[ENCODING_PCM] = "PCM",
[ENCODING_AC3_IEC61937] = "AC3-IEC61937",

View file

@ -379,16 +379,16 @@ static void service_entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupStat
static void publish_service(struct service *s)
{
AvahiStringList *txt = NULL;
const char *t;
char cm[PA_CHANNEL_MAP_SNPRINT_MAX];
const char * const subtype_text[] = {
static const char * const subtype_text[] = {
[SUBTYPE_HARDWARE] = "hardware",
[SUBTYPE_VIRTUAL] = "virtual",
[SUBTYPE_MONITOR] = "monitor"
};
AvahiStringList *txt = NULL;
const char *t;
char cm[PA_CHANNEL_MAP_SNPRINT_MAX];
spa_assert(s);
if (!s->userdata->client || avahi_client_get_state(s->userdata->client) != AVAHI_CLIENT_S_RUNNING)

View file

@ -451,7 +451,7 @@ static void on_core_proxy_destroy(void *data)
client_cleanup(client);
}
static struct pw_proxy_events core_proxy_events = {
static const struct pw_proxy_events core_proxy_events = {
PW_VERSION_CORE_EVENTS,
.destroy = on_core_proxy_destroy,
};

View file

@ -78,8 +78,7 @@ static int client_endpoint_stream_update(void *object,
struct pw_properties *props = NULL;
if (!stream) {
struct pw_context *context = pw_global_get_context(endpoint->global);
const char *keys[] = {
static const char * const keys[] = {
PW_KEY_FACTORY_ID,
PW_KEY_CLIENT_ID,
PW_KEY_ENDPOINT_ID,
@ -90,6 +89,8 @@ static int client_endpoint_stream_update(void *object,
NULL
};
struct pw_context *context = pw_global_get_context(endpoint->global);
stream = calloc(1, sizeof(struct endpoint_stream));
if (!stream)
goto no_mem;
@ -128,7 +129,7 @@ static int client_endpoint_stream_update(void *object,
return -ENOMEM;
}
static struct pw_client_endpoint_methods methods = {
static const struct pw_client_endpoint_methods methods = {
PW_VERSION_CLIENT_ENDPOINT_METHODS,
.update = client_endpoint_update,
.stream_update = client_endpoint_stream_update,

View file

@ -304,7 +304,7 @@ int endpoint_init(struct endpoint *this,
struct pw_context *context,
struct pw_properties *properties)
{
const char *keys[] = {
static const char * const keys[] = {
PW_KEY_FACTORY_ID,
PW_KEY_CLIENT_ID,
PW_KEY_DEVICE_ID,

View file

@ -78,8 +78,7 @@ static int client_session_link_update(void *object,
struct pw_properties *props = NULL;
if (!link) {
struct pw_context *context = pw_global_get_context(session->global);
const char *keys[] = {
static const char * const keys[] = {
PW_KEY_FACTORY_ID,
PW_KEY_CLIENT_ID,
PW_KEY_SESSION_ID,
@ -90,6 +89,8 @@ static int client_session_link_update(void *object,
NULL
};
struct pw_context *context = pw_global_get_context(session->global);
link = calloc(1, sizeof(struct endpoint_link));
if (!link)
goto no_mem;
@ -127,7 +128,7 @@ static int client_session_link_update(void *object,
return -ENOMEM;
}
static struct pw_client_session_methods methods = {
static const struct pw_client_session_methods methods = {
PW_VERSION_CLIENT_SESSION_METHODS,
.update = client_session_update,
.link_update = client_session_link_update,

View file

@ -275,7 +275,7 @@ int session_init(struct session *this,
struct pw_context *context,
struct pw_properties *properties)
{
const char *keys[] = {
static const char * const keys[] = {
PW_KEY_FACTORY_ID,
PW_KEY_CLIENT_ID,
NULL