From b280f163168f6c1036d7a3b0dee552ac68abddf4 Mon Sep 17 00:00:00 2001 From: rubidium42 Date: Wed, 26 May 2021 21:27:28 +0200 Subject: Codechange: remove unneeded comparison and casts Division by resize_y is already yielding an unsigned number, so when clicking in the WD_FRAMERECT_TOP you would already get a huge value, so sel would never be negative. So, leave sel an unsigned number and remove the <= check. --- src/order_gui.cpp | 6 +++--- src/timetable_gui.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/order_gui.cpp b/src/order_gui.cpp index bd1165622..8504ee16f 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -548,13 +548,13 @@ private: VehicleOrderID GetOrderFromPt(int y) { NWidgetBase *nwid = this->GetWidget(WID_O_ORDER_LIST); - int sel = (y - nwid->pos_y - WD_FRAMERECT_TOP) / nwid->resize_y; // Selected line in the WID_O_ORDER_LIST panel. + uint sel = (y - nwid->pos_y - WD_FRAMERECT_TOP) / nwid->resize_y; // Selected line in the WID_O_ORDER_LIST panel. - if ((uint)sel >= this->vscroll->GetCapacity()) return INVALID_VEH_ORDER_ID; + if (sel >= this->vscroll->GetCapacity()) return INVALID_VEH_ORDER_ID; sel += this->vscroll->GetPosition(); - return (sel <= vehicle->GetNumOrders() && sel >= 0) ? sel : INVALID_VEH_ORDER_ID; + return (sel <= vehicle->GetNumOrders()) ? sel : INVALID_VEH_ORDER_ID; } /** diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index af90adc44..fa0e4d114 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -211,13 +211,13 @@ struct TimetableWindow : Window { int GetOrderFromTimetableWndPt(int y, const Vehicle *v) { - int sel = (y - this->GetWidget(WID_VT_TIMETABLE_PANEL)->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_NORMAL; + uint sel = (y - this->GetWidget(WID_VT_TIMETABLE_PANEL)->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_NORMAL; - if ((uint)sel >= this->vscroll->GetCapacity()) return INVALID_ORDER; + if (sel >= this->vscroll->GetCapacity()) return INVALID_ORDER; sel += this->vscroll->GetPosition(); - return (sel < v->GetNumOrders() * 2 && sel >= 0) ? sel : INVALID_ORDER; + return (sel < v->GetNumOrders() * 2u) ? sel : INVALID_ORDER; } /** -- cgit v1.2.3-70-g09d2