Skip to contentSkip to conversation

drm/amd/display: use swap() in sort()

PATCH Applied Jiapeng Chong 3 participants 3 messages Jul 24, 2024 – Jul 25, 2024

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

PATCH 1/1 drm/amd/display: use swap() in sort()

Use existing swap() function rather than duplicating its implementation.

./drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c:17:29-30: WARNING opportunity for swap().

---
 .../display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c    | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c +2 -6
index 717536d7bb30..8e68a8094658 100644
@@ -7,16 +7,12 @@
 
 static void sort(double *list_a, int list_a_size)
 {
-	double temp;
 	// For all elements b[i] in list_b[]
 	for (int i = 0; i < list_a_size - 1; i++) {
 		// Find the first element of list_a that's larger than b[i]
 		for (int j = i; j < list_a_size - 1; j++) {
-			if (list_a[j] > list_a[j + 1]) {
-				temp = list_a[j];
-				list_a[j] = list_a[j + 1];
-				list_a[j + 1] = temp;
-			}
+			if (list_a[j] > list_a[j + 1])
+				swap(list_a[j], list_a[j + 1]);
 		}
 	}
 }
Signature · 1 line
2.32.0.3.g01195cf9f
Applied
#1 lore raw

Applied. Thanks!

Alex

Quoted 38 lines · Jiapeng Chong

Use existing swap() function rather than duplicating its implementation.

./drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c:17:29-30: WARNING opportunity for swap().

---
 .../display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c    | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c +2 -7
index 717536d7bb30..8e68a8094658 100644
@@ -7,16 +7,12 @@
 
 static void sort(double *list_a, int list_a_size)
 {
-       double temp;
        // For all elements b[i] in list_b[]
        for (int i = 0; i < list_a_size - 1; i++) {
                // Find the first element of list_a that's larger than b[i]
                for (int j = i; j < list_a_size - 1; j++) {
-                       if (list_a[j] > list_a[j + 1]) {
-                               temp = list_a[j];
-                               list_a[j] = list_a[j + 1];
-                               list_a[j + 1] = temp;
-                       }
+                       if (list_a[j] > list_a[j + 1])
+                               swap(list_a[j], list_a[j + 1]);
                }
        }
 }
--

2.32.0.3.g01195cf9f

#2 lore raw
In reply to Jiapeng Chong

Am 24.07.24 um 09:37 schrieb Jiapeng Chong:

Quoted 16 lines

Use existing swap() function rather than duplicating its implementation.

./drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c:17:29-30: WARNING opportunity for swap().

---
  .../display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c    | 8 ++------
  1 file changed, 2 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c +0 -0
index 717536d7bb30..8e68a8094658 100644

drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c line 12

Quoted 7 lines
drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c +0 -1
@@ -7,16 +7,12 @@
 
  static void sort(double *list_a, int list_a_size)
  {
-	double temp;
  	// For all elements b[i] in list_b[]
  	for (int i = 0; i < list_a_size - 1; i++) {
  		// Find the first element of list_a that's larger than b[i]

While at it please also replace all // comments by using /* */.

Apart from that looks good to me.

Regards,
Christian.

Quoted 11 lines
drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c +2 -5
  		for (int j = i; j < list_a_size - 1; j++) {
-			if (list_a[j] > list_a[j + 1]) {
-				temp = list_a[j];
-				list_a[j] = list_a[j + 1];
-				list_a[j + 1] = temp;
-			}
+			if (list_a[j] > list_a[j + 1])
+				swap(list_a[j], list_a[j + 1]);
  		}
  	}
  }