sw/source/uibase/uiview/pview.cxx | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)
New commits: commit a2805be648098bb0f7077687d607f35a342efb32 Author: Mike Kaganski <[email protected]> AuthorDate: Sat Aug 2 20:27:12 2025 +0200 Commit: Mike Kaganski <[email protected]> CommitDate: Sun Aug 3 07:23:06 2025 +0200 Use std::find and reverse iterators for simplicity Also there is no need to have {MIN,MAX}_PREVIEW_ZOOM values themselves in aZoomArr. Change-Id: I2ad557cd1b37d1fd287c14072745a62a7114c3dc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188848 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/sw/source/uibase/uiview/pview.cxx b/sw/source/uibase/uiview/pview.cxx index 971191dc866b..8ac6411d118d 100644 --- a/sw/source/uibase/uiview/pview.cxx +++ b/sw/source/uibase/uiview/pview.cxx @@ -68,6 +68,7 @@ #include <svx/svxdlg.hxx> +#include <algorithm> #include <memory> #include <vcl/EnumContext.hxx> #include <vcl/notebookbar/notebookbar.hxx> @@ -98,28 +99,20 @@ void SwPagePreview::InitInterface_Impl() static sal_uInt16 lcl_GetNextZoomStep(sal_uInt16 nCurrentZoom, bool bZoomIn) { - static const sal_uInt16 aZoomArr[] = - { - 25, 50, 75, 100, 150, 200, 400, 600 - }; - const int nZoomArrSize = std::ssize(aZoomArr); + static constexpr sal_uInt16 aZoomArr[] = { 50, 75, 100, 150, 200, 400 }; if (bZoomIn) { - for(sal_uInt16 i : aZoomArr) - { - if(nCurrentZoom < i) - return i; - } + auto it = std::find_if(std::begin(aZoomArr), std::end(aZoomArr), + [nCurrentZoom](sal_uInt16 i) { return nCurrentZoom < i; }); + return it == std::end(aZoomArr) ? MAX_PREVIEW_ZOOM : *it; } else { - for(int i = nZoomArrSize - 1; i >= 0; --i) - { - if(nCurrentZoom > aZoomArr[i] || !i) - return aZoomArr[i]; - } + const std::reverse_iterator r_begin(std::end(aZoomArr)), r_end(std::begin(aZoomArr)); + auto it = std::find_if(r_begin, r_end, + [nCurrentZoom](sal_uInt16 i) { return nCurrentZoom > i; }); + return it == r_end ? MIN_PREVIEW_ZOOM : *it; } - return bZoomIn ? MAX_PREVIEW_ZOOM : MIN_PREVIEW_ZOOM; }; static void lcl_InvalidateZoomSlots(SfxBindings& rBindings)
