summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-11-29 12:40:22 +0100
committerLennart Poettering <lennart@poettering.net>2017-11-29 12:41:08 +0100
commit7b943bb7e3e2fad3481c7191edbfaeef0680b196 (patch)
treecdbc6c8016fef04137c80128eb92f47a057915be
parent5716965132bfad3c897b11799e478820a9587a45 (diff)
downloadsystemd-7b943bb7e3e2fad3481c7191edbfaeef0680b196.tar.gz
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).
-rw-r--r--coccinelle/isempty.cocci15
-rw-r--r--src/core/dbus-execute.c14
-rw-r--r--src/test/test-path-lookup.c2
-rw-r--r--src/tmpfiles/tmpfiles.c2
-rw-r--r--src/udev/collect/collect.c2
5 files changed, 25 insertions, 10 deletions
diff --git a/coccinelle/isempty.cocci b/coccinelle/isempty.cocci
new file mode 100644
index 0000000000..1374ee40d7
--- /dev/null
+++ b/coccinelle/isempty.cocci
@@ -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)
diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c
index 412be2a6c4..14fb46ec59 100644
--- a/src/core/dbus-execute.c
+++ b/src/core/dbus-execute.c
@@ -1108,7 +1108,7 @@ int bus_exec_context_set_transient_property(
}
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
- if (strv_length(l) == 0) {
+ if (strv_isempty(l)) {
c->supplementary_groups = strv_free(c->supplementary_groups);
unit_write_settingf(u, flags, name, "%s=", name);
} else {
@@ -1360,7 +1360,7 @@ int bus_exec_context_set_transient_property(
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
_cleanup_free_ char *joined = NULL;
- if (strv_length(l) == 0) {
+ if (strv_isempty(l)) {
c->syscall_whitelist = false;
c->syscall_filter = hashmap_free(c->syscall_filter);
} else {
@@ -1433,7 +1433,7 @@ int bus_exec_context_set_transient_property(
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
_cleanup_free_ char *joined = NULL;
- if (strv_length(l) == 0)
+ if (strv_isempty(l))
c->syscall_archs = set_free(c->syscall_archs);
else {
char **s;
@@ -1506,7 +1506,7 @@ int bus_exec_context_set_transient_property(
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
_cleanup_free_ char *joined = NULL;
- if (strv_length(l) == 0) {
+ if (strv_isempty(l)) {
c->address_families_whitelist = false;
c->address_families = set_free(c->address_families);
} 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.");
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
- if (strv_length(l) == 0) {
+ if (strv_isempty(l)) {
c->environment = strv_free(c->environment);
unit_write_setting(u, flags, name, "Environment=");
} 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.");
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
- if (strv_length(l) == 0) {
+ if (strv_isempty(l)) {
c->unset_environment = strv_free(c->unset_environment);
unit_write_setting(u, flags, name, "UnsetEnvironment=");
} else {
@@ -2316,7 +2316,7 @@ int bus_exec_context_set_transient_property(
else /* "InaccessiblePaths" */
dirs = &c->inaccessible_paths;
- if (strv_length(l) == 0) {
+ if (strv_isempty(l)) {
*dirs = strv_free(*dirs);
unit_write_settingf(u, flags, name, "%s=", name);
} else {
diff --git a/src/test/test-path-lookup.c b/src/test/test-path-lookup.c
index 94e5d62e64..834b061980 100644
--- a/src/test/test-path-lookup.c
+++ b/src/test/test-path-lookup.c
@@ -47,7 +47,7 @@ static void test_paths(UnitFileScope scope) {
assert_se(strv_length(lp_with_env.search_path) == 1);
assert_se(streq(lp_with_env.search_path[0], systemd_unit_path));
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);
}
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index ad89b46f01..c29087b9d0 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -1788,7 +1788,7 @@ static bool should_include_path(const char *path) {
/* no matches, so we should include this path only if we
* have no whitelist at all */
- if (strv_length(arg_include_prefixes) == 0)
+ if (strv_isempty(arg_include_prefixes))
return true;
log_debug("Entry \"%s\" does not match any include prefix, skipping.", path);
diff --git a/src/udev/collect/collect.c b/src/udev/collect/collect.c
index 14e97e6f48..3e278bd637 100644
--- a/src/udev/collect/collect.c
+++ b/src/udev/collect/collect.c
@@ -162,7 +162,7 @@ static int checkout(int fd)
if (ptr) {
*ptr = '\0';
ptr++;
- if (!strlen(word))
+ if (isempty(word))
continue;
if (debug)