From 14b90daa5a03cd049960d202dda1d6d07742c7b9 Mon Sep 17 00:00:00 2001 From: Mattia Formichetti Date: Tue, 11 Feb 2025 01:40:17 +0100 Subject: [PATCH] core/place: Remove unnecessary sqrt in comparator functions Remove unnecessary sqrt() calls in northwest_cmp and northeast_cmp. The square root would have been necessary if we needed the actual distance, but we only care about the relative order, so it isn't. Part-of: --- src/core/place.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/core/place.c b/src/core/place.c index db79497df..8456934fe 100644 --- a/src/core/place.c +++ b/src/core/place.c @@ -72,9 +72,8 @@ northwest_cmp (gconstpointer a, bx = b_frame.x; by = b_frame.y; - /* probably there's a fast good-enough-guess we could use here. */ - from_origin_a = (int) sqrt (ax * ax + ay * ay); - from_origin_b = (int) sqrt (bx * bx + by * by); + from_origin_a = ax * ax + ay * ay; + from_origin_b = bx * bx + by * by; if (from_origin_a < from_origin_b) return -1; @@ -105,9 +104,8 @@ northeast_cmp (gconstpointer a, bx = (area->x + area->width) - (b_frame.x + b_frame.width); by = b_frame.y; - /* probably there's a fast good-enough-guess we could use here. */ - from_origin_a = (int) sqrt (ax * ax + ay * ay); - from_origin_b = (int) sqrt (bx * bx + by * by); + from_origin_a = ax * ax + ay * ay; + from_origin_b = bx * bx + by * by; if (from_origin_a < from_origin_b) return -1;