Skip to contentSkip to conversation

staging: speakup: selection: replace _manual_ swap with swap macro

PATCH In review Gustavo A. R. Silva 2 participants 2 messages Nov 10, 2017 – Nov 11, 2017 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: speakup: selection: replace _manual_ swap with swap macro

Make use of the swap macro instead of _manually_ swapping values and remove unnecessary variable tmp.

This makes the code easier to read and maintain.

This code was detected with the help of Coccinelle.

---
 drivers/staging/speakup/selection.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/staging/speakup/selection.c +2 -7
index 66061b5..0ed1fef 100644
@@ -64,13 +64,8 @@ int speakup_set_selection(struct tty_struct *tty)
 	ps = spk_ys * vc->vc_size_row + (spk_xs << 1);
 	pe = spk_ye * vc->vc_size_row + (spk_xe << 1);
 
-	if (ps > pe) {
-		/* make sel_start <= sel_end */
-		int tmp = ps;
-
-		ps = pe;
-		pe = tmp;
-	}
+	if (ps > pe)	/* make sel_start <= sel_end */
+		swap(ps, pe);
 
 	if (spk_sel_cons != vc_cons[fg_console].d) {
 		speakup_clear_selection();
Signature · 1 line
2.7.4
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Gustavo A. R. Silva, on ven. 10 nov. 2017 16:13:03 -0600, wrote:

Make use of the swap macro instead of _manually_ swapping values and remove unnecessary variable tmp.

This makes the code easier to read and maintain.

This code was detected with the help of Coccinelle.

Quoted 27 lines
---
 drivers/staging/speakup/selection.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/staging/speakup/selection.c +2 -7
index 66061b5..0ed1fef 100644
@@ -64,13 +64,8 @@ int speakup_set_selection(struct tty_struct *tty)
 	ps = spk_ys * vc->vc_size_row + (spk_xs << 1);
 	pe = spk_ye * vc->vc_size_row + (spk_xe << 1);
 
-	if (ps > pe) {
-		/* make sel_start <= sel_end */
-		int tmp = ps;
-
-		ps = pe;
-		pe = tmp;
-	}
+	if (ps > pe)	/* make sel_start <= sel_end */
+		swap(ps, pe);
 
 	if (spk_sel_cons != vc_cons[fg_console].d) {
 		speakup_clear_selection();
Signature · 1 line
2.7.4
Signature · 7 lines
Samuel
<b> il faut combien de chevaux pour tirer une doloréan à 88 morph ?
***b vient de remarque que 88 mph c'est 142 km/h
<y> aaaaah
<y> c'est pour ça qu'ils limitent à 130 km/h sur les autoroutes
<y> c'est pour éviter que les gens voyagent dans le temps
<b> probablement