summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2014-08-13 01:00:18 +0200
committerMichal Schmidt <mschmidt@redhat.com>2014-09-15 16:08:50 +0200
commitd5099efc47d4e6ac60816b5381a5f607ab03f06e (patch)
tree661308aae8a0885e90da25874e7df3e795532356 /src/core
parentf44541bc934c6e2b02155559e9eeb17a13a09558 (diff)
hashmap: introduce hash_ops to make struct Hashmap smaller
It is redundant to store 'hash' and 'compare' function pointers in struct Hashmap separately. The functions always comprise a pair. Store a single pointer to struct hash_ops instead. systemd keeps hundreds of hashmaps, so this saves a little bit of memory.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/automount.c4
-rw-r--r--src/core/bus-endpoint.c2
-rw-r--r--src/core/dbus-manager.c2
-rw-r--r--src/core/dbus.c2
-rw-r--r--src/core/device.c4
-rw-r--r--src/core/killall.c2
-rw-r--r--src/core/load-fragment.c10
-rw-r--r--src/core/manager.c14
-rw-r--r--src/core/mount-setup.c2
-rw-r--r--src/core/swap.c4
-rw-r--r--src/core/transaction.c2
-rw-r--r--src/core/unit.c22
12 files changed, 35 insertions, 35 deletions
diff --git a/src/core/automount.c b/src/core/automount.c
index 73a8ce17e4..f72aca2957 100644
--- a/src/core/automount.c
+++ b/src/core/automount.c
@@ -685,7 +685,7 @@ static int automount_deserialize_item(Unit *u, const char *key, const char *valu
log_debug_unit(u->id, "Failed to parse token value %s", value);
else {
if (!a->tokens)
- if (!(a->tokens = set_new(trivial_hash_func, trivial_compare_func)))
+ if (!(a->tokens = set_new(NULL)))
return -ENOMEM;
r = set_put(a->tokens, UINT_TO_PTR(token));
@@ -762,7 +762,7 @@ static int automount_dispatch_io(sd_event_source *s, int fd, uint32_t events, vo
} else
log_debug_unit(UNIT(a)->id, "Got direct mount request on %s", a->where);
- r = set_ensure_allocated(&a->tokens, trivial_hash_func, trivial_compare_func);
+ r = set_ensure_allocated(&a->tokens, NULL);
if (r < 0) {
log_error_unit(UNIT(a)->id, "Failed to allocate token set.");
goto fail;
diff --git a/src/core/bus-endpoint.c b/src/core/bus-endpoint.c
index 8d11974db4..1e8f07eb54 100644
--- a/src/core/bus-endpoint.c
+++ b/src/core/bus-endpoint.c
@@ -55,7 +55,7 @@ int bus_endpoint_add_policy(BusEndpoint *ep, const char *name, BusPolicyAccess a
return 0;
}
} else {
- ep->policy_hash = hashmap_new(string_hash_func, string_compare_func);
+ ep->policy_hash = hashmap_new(&string_hash_ops);
if (!ep->policy_hash)
return -ENOMEM;
}
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index 2fe9d193f6..533ce439a7 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -1399,7 +1399,7 @@ static int method_list_unit_files(sd_bus *bus, sd_bus_message *message, void *us
if (r < 0)
return r;
- h = hashmap_new(string_hash_func, string_compare_func);
+ h = hashmap_new(&string_hash_ops);
if (!h)
return -ENOMEM;
diff --git a/src/core/dbus.c b/src/core/dbus.c
index e7eee3c6d1..09b4a4ac6f 100644
--- a/src/core/dbus.c
+++ b/src/core/dbus.c
@@ -659,7 +659,7 @@ static int bus_on_connection(sd_event_source *s, int fd, uint32_t revents, void
return 0;
}
- r = set_ensure_allocated(&m->private_buses, trivial_hash_func, trivial_compare_func);
+ r = set_ensure_allocated(&m->private_buses, NULL);
if (r < 0) {
log_oom();
return 0;
diff --git a/src/core/device.c b/src/core/device.c
index 0f28a16874..11c4261081 100644
--- a/src/core/device.c
+++ b/src/core/device.c
@@ -304,7 +304,7 @@ static int device_update_unit(Manager *m, struct udev_device *dev, const char *p
goto fail;
}
- r = hashmap_ensure_allocated(&m->devices_by_sysfs, string_hash_func, string_compare_func);
+ r = hashmap_ensure_allocated(&m->devices_by_sysfs, &string_hash_ops);
if (r < 0)
goto fail;
@@ -517,7 +517,7 @@ static int device_following_set(Unit *u, Set **_set) {
return 0;
}
- set = set_new(NULL, NULL);
+ set = set_new(NULL);
if (!set)
return -ENOMEM;
diff --git a/src/core/killall.c b/src/core/killall.c
index 291e1f90ee..a6ff50a5a4 100644
--- a/src/core/killall.c
+++ b/src/core/killall.c
@@ -205,7 +205,7 @@ void broadcast_signal(int sig, bool wait_for_exit, bool send_sighup) {
_cleanup_set_free_ Set *pids = NULL;
if (wait_for_exit)
- pids = set_new(trivial_hash_func, trivial_compare_func);
+ pids = set_new(NULL);
assert_se(sigemptyset(&mask) == 0);
assert_se(sigaddset(&mask, SIGCHLD) == 0);
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index 7cf19b93cc..0620882b4e 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -2276,7 +2276,7 @@ int config_parse_syscall_filter(
}
if (!c->syscall_filter) {
- c->syscall_filter = set_new(trivial_hash_func, trivial_compare_func);
+ c->syscall_filter = set_new(NULL);
if (!c->syscall_filter)
return log_oom();
@@ -2368,7 +2368,7 @@ int config_parse_syscall_archs(
return 0;
}
- r = set_ensure_allocated(archs, trivial_hash_func, trivial_compare_func);
+ r = set_ensure_allocated(archs, NULL);
if (r < 0)
return log_oom();
@@ -2474,7 +2474,7 @@ int config_parse_address_families(
}
if (!c->address_families) {
- c->address_families = set_new(trivial_hash_func, trivial_compare_func);
+ c->address_families = set_new(NULL);
if (!c->address_families)
return log_oom();
@@ -3092,7 +3092,7 @@ int config_parse_set_status(
}
}
- r = set_ensure_allocated(&status_set->status, NULL, NULL);
+ r = set_ensure_allocated(&status_set->status, NULL);
if (r < 0)
return log_oom();
@@ -3423,7 +3423,7 @@ static int load_from_path(Unit *u, const char *path) {
assert(u);
assert(path);
- symlink_names = set_new(string_hash_func, string_compare_func);
+ symlink_names = set_new(&string_hash_ops);
if (!symlink_names)
return -ENOMEM;
diff --git a/src/core/manager.c b/src/core/manager.c
index 095111e8c6..0770727cde 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -449,27 +449,27 @@ int manager_new(SystemdRunningAs running_as, bool test_run, Manager **_m) {
if (r < 0)
goto fail;
- r = hashmap_ensure_allocated(&m->units, string_hash_func, string_compare_func);
+ r = hashmap_ensure_allocated(&m->units, &string_hash_ops);
if (r < 0)
goto fail;
- r = hashmap_ensure_allocated(&m->jobs, trivial_hash_func, trivial_compare_func);
+ r = hashmap_ensure_allocated(&m->jobs, NULL);
if (r < 0)
goto fail;
- r = hashmap_ensure_allocated(&m->cgroup_unit, string_hash_func, string_compare_func);
+ r = hashmap_ensure_allocated(&m->cgroup_unit, &string_hash_ops);
if (r < 0)
goto fail;
- r = hashmap_ensure_allocated(&m->watch_bus, string_hash_func, string_compare_func);
+ r = hashmap_ensure_allocated(&m->watch_bus, &string_hash_ops);
if (r < 0)
goto fail;
- r = set_ensure_allocated(&m->startup_units, trivial_hash_func, trivial_compare_func);
+ r = set_ensure_allocated(&m->startup_units, NULL);
if (r < 0)
goto fail;
- r = set_ensure_allocated(&m->failed_units, trivial_hash_func, trivial_compare_func);
+ r = set_ensure_allocated(&m->failed_units, NULL);
if (r < 0)
goto fail;
@@ -903,7 +903,7 @@ static void manager_build_unit_path_cache(Manager *m) {
set_free_free(m->unit_path_cache);
- m->unit_path_cache = set_new(string_hash_func, string_compare_func);
+ m->unit_path_cache = set_new(&string_hash_ops);
if (!m->unit_path_cache) {
log_error("Failed to allocate unit path cache.");
return;
diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c
index cc2633e3bd..23a66d2e95 100644
--- a/src/core/mount-setup.c
+++ b/src/core/mount-setup.c
@@ -235,7 +235,7 @@ int mount_cgroup_controllers(char ***join_controllers) {
return 0;
}
- controllers = set_new(string_hash_func, string_compare_func);
+ controllers = set_new(&string_hash_ops);
if (!controllers)
return log_oom();
diff --git a/src/core/swap.c b/src/core/swap.c
index 019d32ed0d..b88a914f72 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -77,7 +77,7 @@ static int swap_set_devnode(Swap *s, const char *devnode) {
assert(s);
- r = hashmap_ensure_allocated(&UNIT(s)->manager->swaps_by_devnode, string_hash_func, string_compare_func);
+ r = hashmap_ensure_allocated(&UNIT(s)->manager->swaps_by_devnode, &string_hash_ops);
if (r < 0)
return r;
@@ -1226,7 +1226,7 @@ static int swap_following_set(Unit *u, Set **_set) {
return 0;
}
- set = set_new(NULL, NULL);
+ set = set_new(NULL);
if (!set)
return -ENOMEM;
diff --git a/src/core/transaction.c b/src/core/transaction.c
index 1f4c9ce416..dbb4133fe3 100644
--- a/src/core/transaction.c
+++ b/src/core/transaction.c
@@ -1143,7 +1143,7 @@ Transaction *transaction_new(bool irreversible) {
if (!tr)
return NULL;
- tr->jobs = hashmap_new(trivial_hash_func, trivial_compare_func);
+ tr->jobs = hashmap_new(NULL);
if (!tr->jobs) {
free(tr);
return NULL;
diff --git a/src/core/unit.c b/src/core/unit.c
index b5c3182940..5978e21f56 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -81,7 +81,7 @@ Unit *unit_new(Manager *m, size_t size) {
if (!u)
return NULL;
- u->names = set_new(string_hash_func, string_compare_func);
+ u->names = set_new(&string_hash_ops);
if (!u->names) {
free(u);
return NULL;
@@ -1843,17 +1843,17 @@ int unit_watch_pid(Unit *u, pid_t pid) {
/* Watch a specific PID. We only support one or two units
* watching each PID for now, not more. */
- r = set_ensure_allocated(&u->pids, trivial_hash_func, trivial_compare_func);
+ r = set_ensure_allocated(&u->pids, NULL);
if (r < 0)
return r;
- r = hashmap_ensure_allocated(&u->manager->watch_pids1, trivial_hash_func, trivial_compare_func);
+ r = hashmap_ensure_allocated(&u->manager->watch_pids1, NULL);
if (r < 0)
return r;
r = hashmap_put(u->manager->watch_pids1, LONG_TO_PTR(pid), u);
if (r == -EEXIST) {
- r = hashmap_ensure_allocated(&u->manager->watch_pids2, trivial_hash_func, trivial_compare_func);
+ r = hashmap_ensure_allocated(&u->manager->watch_pids2, NULL);
if (r < 0)
return r;
@@ -2086,22 +2086,22 @@ int unit_add_dependency(Unit *u, UnitDependency d, Unit *other, bool add_referen
return 0;
}
- r = set_ensure_allocated(&u->dependencies[d], trivial_hash_func, trivial_compare_func);
+ r = set_ensure_allocated(&u->dependencies[d], NULL);
if (r < 0)
return r;
if (inverse_table[d] != _UNIT_DEPENDENCY_INVALID) {
- r = set_ensure_allocated(&other->dependencies[inverse_table[d]], trivial_hash_func, trivial_compare_func);
+ r = set_ensure_allocated(&other->dependencies[inverse_table[d]], NULL);
if (r < 0)
return r;
}
if (add_reference) {
- r = set_ensure_allocated(&u->dependencies[UNIT_REFERENCES], trivial_hash_func, trivial_compare_func);
+ r = set_ensure_allocated(&u->dependencies[UNIT_REFERENCES], NULL);
if (r < 0)
return r;
- r = set_ensure_allocated(&other->dependencies[UNIT_REFERENCED_BY], trivial_hash_func, trivial_compare_func);
+ r = set_ensure_allocated(&other->dependencies[UNIT_REFERENCED_BY], NULL);
if (r < 0)
return r;
}
@@ -2847,7 +2847,7 @@ static Set *unit_pid_set(pid_t main_pid, pid_t control_pid) {
Set *pid_set;
int r;
- pid_set = set_new(trivial_hash_func, trivial_compare_func);
+ pid_set = set_new(NULL);
if (!pid_set)
return NULL;
@@ -3385,7 +3385,7 @@ int unit_require_mounts_for(Unit *u, const char *path) {
char *q;
if (!u->manager->units_requiring_mounts_for) {
- u->manager->units_requiring_mounts_for = hashmap_new(string_hash_func, string_compare_func);
+ u->manager->units_requiring_mounts_for = hashmap_new(&string_hash_ops);
if (!u->manager->units_requiring_mounts_for)
return -ENOMEM;
}
@@ -3394,7 +3394,7 @@ int unit_require_mounts_for(Unit *u, const char *path) {
if (!q)
return -ENOMEM;
- x = set_new(NULL, NULL);
+ x = set_new(NULL);
if (!x) {
free(q);
return -ENOMEM;