mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-22 13:33:56 +03:00
tree-wide: use strv_isempty() instead of strv_length() == 0
It's a lot faster in many cases, since it's O(1) rather than O(n).
This commit is contained in:
parent
5716965132
commit
7b943bb7e3
15
coccinelle/isempty.cocci
Normal file
15
coccinelle/isempty.cocci
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
@@
|
||||||
|
expression s;
|
||||||
|
@@
|
||||||
|
- strv_length(s) == 0
|
||||||
|
+ strv_isempty(s)
|
||||||
|
@@
|
||||||
|
expression s;
|
||||||
|
@@
|
||||||
|
- strlen(s) == 0
|
||||||
|
+ isempty(s)
|
||||||
|
@@
|
||||||
|
expression s;
|
||||||
|
@@
|
||||||
|
- strlen_ptr(s) == 0
|
||||||
|
+ isempty(s)
|
@ -1108,7 +1108,7 @@ int bus_exec_context_set_transient_property(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||||
if (strv_length(l) == 0) {
|
if (strv_isempty(l)) {
|
||||||
c->supplementary_groups = strv_free(c->supplementary_groups);
|
c->supplementary_groups = strv_free(c->supplementary_groups);
|
||||||
unit_write_settingf(u, flags, name, "%s=", name);
|
unit_write_settingf(u, flags, name, "%s=", name);
|
||||||
} else {
|
} else {
|
||||||
@ -1360,7 +1360,7 @@ int bus_exec_context_set_transient_property(
|
|||||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||||
_cleanup_free_ char *joined = NULL;
|
_cleanup_free_ char *joined = NULL;
|
||||||
|
|
||||||
if (strv_length(l) == 0) {
|
if (strv_isempty(l)) {
|
||||||
c->syscall_whitelist = false;
|
c->syscall_whitelist = false;
|
||||||
c->syscall_filter = hashmap_free(c->syscall_filter);
|
c->syscall_filter = hashmap_free(c->syscall_filter);
|
||||||
} else {
|
} else {
|
||||||
@ -1433,7 +1433,7 @@ int bus_exec_context_set_transient_property(
|
|||||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||||
_cleanup_free_ char *joined = NULL;
|
_cleanup_free_ char *joined = NULL;
|
||||||
|
|
||||||
if (strv_length(l) == 0)
|
if (strv_isempty(l))
|
||||||
c->syscall_archs = set_free(c->syscall_archs);
|
c->syscall_archs = set_free(c->syscall_archs);
|
||||||
else {
|
else {
|
||||||
char **s;
|
char **s;
|
||||||
@ -1506,7 +1506,7 @@ int bus_exec_context_set_transient_property(
|
|||||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||||
_cleanup_free_ char *joined = NULL;
|
_cleanup_free_ char *joined = NULL;
|
||||||
|
|
||||||
if (strv_length(l) == 0) {
|
if (strv_isempty(l)) {
|
||||||
c->address_families_whitelist = false;
|
c->address_families_whitelist = false;
|
||||||
c->address_families = set_free(c->address_families);
|
c->address_families = set_free(c->address_families);
|
||||||
} else {
|
} else {
|
||||||
@ -2073,7 +2073,7 @@ int bus_exec_context_set_transient_property(
|
|||||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment block.");
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment block.");
|
||||||
|
|
||||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||||
if (strv_length(l) == 0) {
|
if (strv_isempty(l)) {
|
||||||
c->environment = strv_free(c->environment);
|
c->environment = strv_free(c->environment);
|
||||||
unit_write_setting(u, flags, name, "Environment=");
|
unit_write_setting(u, flags, name, "Environment=");
|
||||||
} else {
|
} else {
|
||||||
@ -2109,7 +2109,7 @@ int bus_exec_context_set_transient_property(
|
|||||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid UnsetEnvironment= list.");
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid UnsetEnvironment= list.");
|
||||||
|
|
||||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||||
if (strv_length(l) == 0) {
|
if (strv_isempty(l)) {
|
||||||
c->unset_environment = strv_free(c->unset_environment);
|
c->unset_environment = strv_free(c->unset_environment);
|
||||||
unit_write_setting(u, flags, name, "UnsetEnvironment=");
|
unit_write_setting(u, flags, name, "UnsetEnvironment=");
|
||||||
} else {
|
} else {
|
||||||
@ -2316,7 +2316,7 @@ int bus_exec_context_set_transient_property(
|
|||||||
else /* "InaccessiblePaths" */
|
else /* "InaccessiblePaths" */
|
||||||
dirs = &c->inaccessible_paths;
|
dirs = &c->inaccessible_paths;
|
||||||
|
|
||||||
if (strv_length(l) == 0) {
|
if (strv_isempty(l)) {
|
||||||
*dirs = strv_free(*dirs);
|
*dirs = strv_free(*dirs);
|
||||||
unit_write_settingf(u, flags, name, "%s=", name);
|
unit_write_settingf(u, flags, name, "%s=", name);
|
||||||
} else {
|
} else {
|
||||||
|
@ -47,7 +47,7 @@ static void test_paths(UnitFileScope scope) {
|
|||||||
assert_se(strv_length(lp_with_env.search_path) == 1);
|
assert_se(strv_length(lp_with_env.search_path) == 1);
|
||||||
assert_se(streq(lp_with_env.search_path[0], systemd_unit_path));
|
assert_se(streq(lp_with_env.search_path[0], systemd_unit_path));
|
||||||
assert_se(lookup_paths_reduce(&lp_with_env) >= 0);
|
assert_se(lookup_paths_reduce(&lp_with_env) >= 0);
|
||||||
assert_se(strv_length(lp_with_env.search_path) == 0);
|
assert_se(strv_isempty(lp_with_env.search_path));
|
||||||
|
|
||||||
assert_se(rm_rf(template, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
|
assert_se(rm_rf(template, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
|
||||||
}
|
}
|
||||||
|
@ -1788,7 +1788,7 @@ static bool should_include_path(const char *path) {
|
|||||||
|
|
||||||
/* no matches, so we should include this path only if we
|
/* no matches, so we should include this path only if we
|
||||||
* have no whitelist at all */
|
* have no whitelist at all */
|
||||||
if (strv_length(arg_include_prefixes) == 0)
|
if (strv_isempty(arg_include_prefixes))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
log_debug("Entry \"%s\" does not match any include prefix, skipping.", path);
|
log_debug("Entry \"%s\" does not match any include prefix, skipping.", path);
|
||||||
|
@ -162,7 +162,7 @@ static int checkout(int fd)
|
|||||||
if (ptr) {
|
if (ptr) {
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
ptr++;
|
ptr++;
|
||||||
if (!strlen(word))
|
if (isempty(word))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
|
Loading…
Reference in New Issue
Block a user