[lvm-devel] [PATCH 17/29] Optimize second call to strchr with same parameters

Zdenek Kabelac zkabelac at redhat.com
Thu Nov 25 10:55:21 UTC 2010


Add tempory char* to keep result of strchr call.
Make also static analysis happier as lv_name is now tested for nonnull.

Signed-off-by: Zdenek Kabelac <zkabelac at redhat.com>
---
 tools/toollib.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/toollib.c b/tools/toollib.c
index 9af1630..f6ba45b 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -214,6 +214,7 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv,
 
 		for (; opt < argc; opt++) {
 			const char *lv_name = argv[opt];
+			const char *tmp_lv_name;
 			char *vgname_def;
 			unsigned dev_dir_found = 0;
 
@@ -246,9 +247,9 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv,
 				continue;
 			}
 			lv_name = vgname;
-			if (strchr(vgname, '/')) {
+			if ((tmp_lv_name = strchr(vgname, '/'))) {
 				/* Must be an LV */
-				lv_name = strchr(vgname, '/');
+				lv_name = tmp_lv_name;
 				while (*lv_name == '/')
 					lv_name++;
 				if (!(vgname = extract_vgname(cmd, vgname))) {
-- 
1.7.3.2




More information about the lvm-devel mailing list