1 |
commit: 9b843f5c9d0a5bdd4a57efb5bd5f41c4736d4dcf |
2 |
Author: Kenneth Raplee <kenrap <AT> kennethraplee <DOT> com> |
3 |
AuthorDate: Tue Mar 22 07:46:22 2022 +0000 |
4 |
Commit: Sam James <sam <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Mar 27 23:06:41 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=9b843f5c |
7 |
|
8 |
Consolidate nested conditional branches |
9 |
|
10 |
Depending how a conditional is wrote, its nested conditional can be |
11 |
consolidated into its own expression by using the `and` or `or` boolean |
12 |
operators for the same effect. These kinds of refactors give processors |
13 |
better chances at branch prediction and would make these conditionals |
14 |
less expensive than they might have been. |
15 |
|
16 |
Signed-off-by: Kenneth Raplee <kenrap <AT> kennethraplee.com> |
17 |
Signed-off-by: Sam James <sam <AT> gentoo.org> |
18 |
|
19 |
lib/portage/checksum.py | 5 ++--- |
20 |
lib/portage/data.py | 9 ++------- |
21 |
lib/portage/dispatch_conf.py | 18 +++++++++++------- |
22 |
3 files changed, 15 insertions(+), 17 deletions(-) |
23 |
|
24 |
diff --git a/lib/portage/checksum.py b/lib/portage/checksum.py |
25 |
index 3b5a10d24..d7e800c47 100644 |
26 |
--- a/lib/portage/checksum.py |
27 |
+++ b/lib/portage/checksum.py |
28 |
@@ -427,9 +427,8 @@ class _hash_filter: |
29 |
for token in self._tokens: |
30 |
if token in matches: |
31 |
return True |
32 |
- if token[:1] == "-": |
33 |
- if token[1:] in matches: |
34 |
- return False |
35 |
+ if token[:1] == "-" and token[1:] in matches: |
36 |
+ return False |
37 |
return False |
38 |
|
39 |
|
40 |
|
41 |
diff --git a/lib/portage/data.py b/lib/portage/data.py |
42 |
index de7d88e5e..b73fa8882 100644 |
43 |
--- a/lib/portage/data.py |
44 |
+++ b/lib/portage/data.py |
45 |
@@ -158,15 +158,12 @@ def _get_global(k): |
46 |
unprivileged = _unprivileged_mode(eroot_or_parent, eroot_st) |
47 |
|
48 |
v = 0 |
49 |
- if uid == 0: |
50 |
- v = 2 |
51 |
- elif unprivileged: |
52 |
+ if uid == 0 or unprivileged: |
53 |
v = 2 |
54 |
elif _get_global("portage_gid") in os.getgroups(): |
55 |
v = 1 |
56 |
|
57 |
elif k in ("portage_gid", "portage_uid"): |
58 |
- |
59 |
# Discover the uid and gid of the portage user/group |
60 |
keyerror = False |
61 |
try: |
62 |
@@ -357,9 +354,7 @@ def _init(settings): |
63 |
|
64 |
if "secpass" not in _initialized_globals: |
65 |
v = 0 |
66 |
- if uid == 0: |
67 |
- v = 2 |
68 |
- elif "unprivileged" in settings.features: |
69 |
+ if uid == 0 or "unprivileged" in settings.features: |
70 |
v = 2 |
71 |
elif portage_gid in os.getgroups(): |
72 |
v = 1 |
73 |
|
74 |
diff --git a/lib/portage/dispatch_conf.py b/lib/portage/dispatch_conf.py |
75 |
index c89caf087..d682a9ad0 100644 |
76 |
--- a/lib/portage/dispatch_conf.py |
77 |
+++ b/lib/portage/dispatch_conf.py |
78 |
@@ -238,13 +238,17 @@ def rcs_archive(archive, curconf, newconf, mrgconf): |
79 |
|
80 |
_archive_copy(mystat, newconf, archive) |
81 |
|
82 |
- if has_branch: |
83 |
- if mrgconf and os.path.isfile(archive) and os.path.isfile(mrgconf): |
84 |
- # This puts the results of the merge into mrgconf. |
85 |
- ret = os.system(f"rcsmerge -p -r{RCS_BRANCH} '{archive}' > '{mrgconf}'") |
86 |
- os.chmod(mrgconf, mystat.st_mode) |
87 |
- os.chown(mrgconf, mystat.st_uid, mystat.st_gid) |
88 |
- os.rename(archive, archive + ".dist.new") |
89 |
+ if ( |
90 |
+ has_branch |
91 |
+ and mrgconf |
92 |
+ and os.path.isfile(archive) |
93 |
+ and os.path.isfile(mrgconf) |
94 |
+ ): |
95 |
+ # This puts the results of the merge into mrgconf. |
96 |
+ ret = os.system(f"rcsmerge -p -r{RCS_BRANCH} '{archive}' > '{mrgconf}'") |
97 |
+ os.chmod(mrgconf, mystat.st_mode) |
98 |
+ os.chown(mrgconf, mystat.st_uid, mystat.st_gid) |
99 |
+ os.rename(archive, f"{archive}.dist.new") |
100 |
|
101 |
return ret |