staging: lustre: libcfs: use swap() in cfs_hash_bd_order()
PATCH 1/1 staging: lustre: libcfs: use swap() in cfs_hash_bd_order()
Use swap() function instead of using a temporary variable for swapping two variables.
The Coccinelle semantic patch used to make this change is as follows:
//<smpl>
@@
type T;
T a,b,c;
@@
- a = b;
- b = c;
- c = a;
+ swap(b, c);
//<smpl>
Additionally cleaned up the if-else block.
--- drivers/staging/lustre/lustre/libcfs/hash.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/staging/lustre/lustre/libcfs/hash.c +3 -9
@@ -800,16 +800,10 @@ cfs_hash_bd_order(struct cfs_hash_bd *bd1, struct cfs_hash_bd *bd2) } rc =cfs_hash_bd_compare (bd1, bd2); -if (rc ==0 ) { +if (!rc) bd2->bd_bucket =NULL ; - - }else if (rc >0 ) {/* swab bd1 and bd2 */ -struct cfs_hash_bd tmp; - - tmp = *bd2; - *bd2 = *bd1; - *bd1 = tmp; - } +else if (rc >0 ) +swap (*bd1, *bd2);/* swab bd1 and bd2 */ }void
Signature · 1 line
1.9.1
Quoted 27 lines · Amitoj Kaur Chawla
Use
swap()function instead of using a temporary variable for swapping two variables.The Coccinelle semantic patch used to make this change is as follows:
//<smpl>
@@
type T;
T a,b,c;
@@
- a = b;
- b = c;
- c = a;
+swap(b, c);
//<smpl>Additionally cleaned up the if-else block.
Signed-off-by Amitoj Kaur Chawla <[email protected]>--- drivers/staging/lustre/lustre/libcfs/hash.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)drivers/staging/lustre/lustre/libcfs/hash.c +0
-0
drivers/staging/lustre/lustre/libcfs/hash.c cfs_hash_bd_order(struct cfs_hash_bd *bd1, struct cfs_hash_bd *bd2) · line 803
Quoted 5 lines
drivers/staging/lustre/lustre/libcfs/hash.c +1
-1@@ -800,16 +800,10 @@ cfs_hash_bd_order(struct cfs_hash_bd *bd1, struct cfs_hash_bd *bd2) } rc =cfs_hash_bd_compare (bd1, bd2); -if (rc ==0 ) { +if (!rc)
This seems like a completely different issue than the use of swap.
julia
Quoted 24 lines
drivers/staging/lustre/lustre/libcfs/hash.c +2
-8bd2->bd_bucket =NULL ; - - }else if (rc >0 ) {/* swab bd1 and bd2 */ -struct cfs_hash_bd tmp; - - tmp = *bd2; - *bd2 = *bd1; - *bd1 = tmp; - } + else if (rc > 0) + swap(*bd1, *bd2); /* swab bd1 and bd2 */ }void Signature · 8 lines
1.9.1 -- You received this message because you are subscribed to the Google Groups "outreachy-kernel" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20160223133302.GA3944%40amitoj-Inspiron-3542. For more options, visit https://groups.google.com/d/optout.
Quoted 9 lines · Julia Lawall
drivers/staging/lustre/lustre/libcfs/hash.c cfs_hash_bd_order(struct cfs_hash_bd *bd1, struct cfs_hash_bd *bd2) · line 803
Quoted 4 lines
rc = cfs_hash_bd_compare(bd1, bd2);drivers/staging/lustre/lustre/libcfs/hash.c +1
-1-if (rc ==0 ) { +if (!rc)This seems like a completely different issue than the use of swap.
julia
I thought it would be okay to clean up the entire if-else block in the same patch and not just the else condition.
If you prefer me sticking to only the swap cleanup, I'll do that.
Amitoj
Quoted 6 lines · Amitoj Kaur Chawla
Quoted 5 lines · Julia Lawall
Quoted 4 lines
rc = cfs_hash_bd_compare(bd1, bd2);drivers/staging/lustre/lustre/libcfs/hash.c +1
-1-if (rc ==0 ) { +if (!rc)
Quoted 8 lines
Quoted 4 lines
This seems like a completely different issue than the use of swap.
julia
I thought it would be okay to clean up the entire if-else block in the same patch and not just the else condition.
If you prefer me sticking to only the swap cleanup, I'll do that.
Yes, it would be better. The swap has really nothing to do with the if. You can also make a series with the other change, to get it done.
julia
Quoted 10 lines
Amitoj
Signature · 5 lines
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/CA%2B5yK5Ey6zJzef7jzbgsUk2TYYZ_%2BAdJ8Suk7L6PKYGepzwHRw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Quoted 6 lines · Julia Lawall
Yes, it would be better. The swap has really nothing to do with the if. You can also make a series with the other change, to get it done.
julia
Okay, will send a series.
Amitoj