Skip to contentSkip to conversation

lib/vsprintf.c:Avoid extra operation in dentry_name

PATCH In review Anshul Garg 2 participants 3 messages Feb 16, 2015 – Feb 17, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/vsprintf.c:Avoid extra operation in dentry_name

From: Anshul Garg <[email protected]>

Remove unnecessary increment and decrement operation in dentry_name function as after increment operation loop is breaked and then decrement operation is performed. So remove increment and decrement operation from the function.

---
 lib/vsprintf.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
lib/vsprintf.c +1 -2
index ec337f6..2a38105 100644
@@ -576,11 +576,10 @@ char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_sp
 		if (p == d) {
 			if (i)
 				array[i] = "";
-			i++;
 			break;
 		}
 	}
-	s = array[--i];
+	s = array[i];
 	for (n = 0; n != spec.precision; n++, buf++) {
 		char c = *s++;
 		if (!c) {
Signature · 6 lines
1.7.9.5


---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com
#1 lore raw
Quoted 20 lines · Anshul Garg

From: Anshul Garg <[email protected]>

Remove unnecessary increment and decrement operation in dentry_name function as after increment operation loop is breaked and then decrement operation is performed. So remove increment and decrement operation from the function.

---
 lib/vsprintf.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
lib/vsprintf.c +0 -0
index ec337f6..2a38105 100644
@@ -576,11 +576,10 @@ char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_sp
                if (p == d) {
                        if (i)

lib/vsprintf.c char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_sp · line 585

Quoted 10 lines
lib/vsprintf.c +1 -2
                                array[i] = "";
-                       i++;
                        break;
                }
        }
-       s = array[--i];
+       s = array[i];
        for (n = 0; n != spec.precision; n++, buf++) {
                char c = *s++;
                if (!c) {

What if the if (d == d) branch is not taken? Does the code then really behave exactly as before?

Signature · 2 lines
Thanks,
//richard
#2 lore raw

Yes suggested code modification will break if (p==d) branch is not taken. Thanks for pointing out this point.

So its better to keep code as it is.

Quoted 38 lines · Richard Weinberger
Quoted 20 lines · Anshul Garg

From: Anshul Garg <[email protected]>

Remove unnecessary increment and decrement operation in dentry_name function as after increment operation loop is breaked and then decrement operation is performed. So remove increment and decrement operation from the function.

---
 lib/vsprintf.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
lib/vsprintf.c +0 -0
index ec337f6..2a38105 100644
@@ -576,11 +576,10 @@ char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_sp
                if (p == d) {
                        if (i)

lib/vsprintf.c char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_sp · line 585

Quoted 10 lines
lib/vsprintf.c +1 -2
                                array[i] = "";
-                       i++;
                        break;
                }
        }
-       s = array[--i];
+       s = array[i];
        for (n = 0; n != spec.precision; n++, buf++) {
                char c = *s++;
                if (!c) {

What if the if (d == d) branch is not taken? Does the code then really behave exactly as before?

--
Thanks,
//richard