代码拉取完成,页面将自动刷新
同步操作将从 yangshicheng/systemd 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From 4b7918a65cc2571a2b3fc166229e1b8db463e217 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Thu, 17 Nov 2022 12:46:45 +0900
Subject: [PATCH] core/unit: merge two loops into one
No functional change, just refactoring.
---
src/core/unit.c | 47 +++++++++++++++--------------------------------
1 file changed, 15 insertions(+), 32 deletions(-)
diff --git a/src/core/unit.c b/src/core/unit.c
index a9052428e4..0d52e4bf1a 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -1048,7 +1048,6 @@ static void unit_merge_dependencies(Unit *u, Unit *other) {
Hashmap *deps;
void *dt; /* Actually of type UnitDependency, except that we don't bother casting it here,
* since the hashmaps all want it as void pointer. */
- int r;
assert(u);
assert(other);
@@ -1075,6 +1074,8 @@ static void unit_merge_dependencies(Unit *u, Unit *other) {
if (!other_deps)
break; /* done! */
+ deps = hashmap_get(u->dependencies, dt);
+
/* Now iterate through all dependencies of this dependency type, of 'other'. We refer to the
* referenced units as 'back'. */
HASHMAP_FOREACH_KEY(di_back.data, back, other_deps) {
@@ -1085,6 +1086,7 @@ static void unit_merge_dependencies(Unit *u, Unit *other) {
/* This is a dependency pointing back to the unit we want to merge with?
* Suppress it (but warn) */
unit_maybe_warn_about_dependency(u, other->id, UNIT_DEPENDENCY_FROM_PTR(dt));
+ hashmap_remove(other_deps, back);
continue;
}
@@ -1103,40 +1105,21 @@ static void unit_merge_dependencies(Unit *u, Unit *other) {
di_move.origin_mask,
di_move.destination_mask) >= 0);
}
- }
- /* Now all references towards 'other' of the current type 'dt' are corrected to point to
- * 'u'. Lets's now move the deps of type 'dt' from 'other' to 'u'. First, let's try to move
- * them per type wholesale. */
- r = hashmap_put(u->dependencies, dt, other_deps);
- if (r == -EEXIST) {
/* The target unit already has dependencies of this type, let's then merge this individually. */
-
- assert_se(deps = hashmap_get(u->dependencies, dt));
-
- for (;;) {
- UnitDependencyInfo di_move;
-
- /* Get first dep */
- di_move.data = hashmap_steal_first_key_and_value(other_deps, (void**) &back);
- if (!di_move.data)
- break; /* done */
- if (back == u) {
- /* Would point back to us, ignore */
- unit_maybe_warn_about_dependency(u, other->id, UNIT_DEPENDENCY_FROM_PTR(dt));
- continue;
- }
-
- assert_se(unit_per_dependency_type_hashmap_update(deps, back, di_move.origin_mask, di_move.destination_mask) >= 0);
- }
- } else {
- assert_se(r >= 0);
-
- if (hashmap_remove(other_deps, u))
- unit_maybe_warn_about_dependency(u, other->id, UNIT_DEPENDENCY_FROM_PTR(dt));
-
- TAKE_PTR(other_deps);
+ if (deps)
+ assert_se(unit_per_dependency_type_hashmap_update(
+ deps,
+ back,
+ di_back.origin_mask,
+ di_back.destination_mask) >= 0);
}
+
+ /* Now all references towards 'other' of the current type 'dt' are corrected to point to 'u'.
+ * Lets's now move the deps of type 'dt' from 'other' to 'u'. If the unit does not have
+ * dependencies of this type, let's move them per type wholesale. */
+ if (!deps)
+ assert_se(hashmap_put(u->dependencies, dt, TAKE_PTR(other_deps)) >= 0);
}
other->dependencies = hashmap_free(other->dependencies);
--
2.27.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。