From 5a71deda15f15f3658bc22db9cc71767a851d17e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Tue, 22 Oct 2024 09:06:09 +0200 Subject: [PATCH] Optimization --- src/map/dem.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/map/dem.cpp b/src/map/dem.cpp index fa3b8920..28e45ba5 100644 --- a/src/map/dem.cpp +++ b/src/map/dem.cpp @@ -23,12 +23,20 @@ static unsigned int isqrt(unsigned int x) { - unsigned int r = 0; + unsigned int l = 0; + unsigned int m; + unsigned int r = x + 1; - while ((r + 1) * (r + 1) <= x) - r++; + while (l != r - 1) { + m = (l + r) / 2; - return r; + if (m * m <= x) + l = m; + else + r = m; + } + + return l; } static double interpolate(double dx, double dy, double p0, double p1, double p2,