Skip to contentSkip to conversation

Staging: rtl8188eu: Refactor loop to increase compactness

PATCH In review Vatika Harlalka 2 participants 4 messages Feb 27, 2015 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: rtl8188eu: Refactor loop to increase compactness

The variables tmp1 and tmp2 are assigned the same values in the nested else and the outer else. They can be assigned without nesting to increase readability.

---
 drivers/staging/rtl8188eu/hal/phy.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/staging/rtl8188eu/hal/phy.c +2 -8
index 3d0e447..05379be 100644
@@ -1039,18 +1039,12 @@ static bool simularity_compare(struct adapter *adapt, s32 resulta[][8],
 
 	for (i = 0; i < bound; i++) {
 		if (i%2 == 1) {
+			tmp1 = resulta[c1][i];
+			tmp2 = resulta[c2][i];
 			if ((resulta[c1][i] & 0x00000200) != 0)
 				tmp1 = resulta[c1][i] | 0xFFFFFC00;
-			else
-				tmp1 = resulta[c1][i];
-
 			if ((resulta[c2][i] & 0x00000200) != 0)
 				tmp2 = resulta[c2][i] | 0xFFFFFC00;
-			else
-				tmp2 = resulta[c2][i];
-		} else {
-			tmp1 = resulta[c1][i];
-			tmp2 = resulta[c2][i];
 		}
 
 		diff = (tmp1 > tmp2) ? (tmp1 - tmp2) : (tmp2 - tmp1);
Signature · 1 line
1.9.1
#1 lore raw
Quoted 14 lines · Vatika Harlalka

The variables tmp1 and tmp2 are assigned the same values in the nested else and the outer else. They can be assigned without nesting to increase readability.

---
 drivers/staging/rtl8188eu/hal/phy.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/staging/rtl8188eu/hal/phy.c +0 -0
index 3d0e447..05379be 100644

drivers/staging/rtl8188eu/hal/phy.c static bool simularity_compare(struct adapter *adapt, s32 resulta[][8], · line 1043

Quoted 5 lines
drivers/staging/rtl8188eu/hal/phy.c +2 -0
@@ -1039,18 +1039,12 @@ static bool simularity_compare(struct adapter *adapt, s32 resulta[][8],
 
 	for (i = 0; i < bound; i++) {
 		if (i%2 == 1) {
+			tmp1 = resulta[c1][i];
+			tmp2 = resulta[c2][i];

I find this confusing. There is an assignment that is just there to be written over in one case.

julia

Quoted 25 lines
drivers/staging/rtl8188eu/hal/phy.c +0 -9
 			if ((resulta[c1][i] & 0x00000200) != 0)
 				tmp1 = resulta[c1][i] | 0xFFFFFC00;
-			else
-				tmp1 = resulta[c1][i];
-
 			if ((resulta[c2][i] & 0x00000200) != 0)
 				tmp2 = resulta[c2][i] | 0xFFFFFC00;
-			else
-				tmp2 = resulta[c2][i];
-		} else {
-			tmp1 = resulta[c1][i];
-			tmp2 = resulta[c2][i];
 		}
 
 		diff = (tmp1 > tmp2) ? (tmp1 - tmp2) : (tmp2 - tmp1);
--

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/20150227180728.GA22813%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

#2 lore raw

My understanding was that since the inner nested else and the outer else were doing the same thing, we could make it more compact by assigning it before-hand and only updating the values when required.

#3 lore raw
Quoted 4 lines · Vatika Harlalka

My understanding was that since the inner nested else and the outer else were doing the same thing, we could make it more compact by assigning it before-hand and only updating the values when required.

I agree that the transformation is correct. But I think that the result could be confusing.

Good effort to think about these things though :)

julia