From caa6195caa451a765c045d3f37f44007a7428106 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Tue, 12 Mar 2024 16:09:12 +0400 Subject: [PATCH] Tidied up TabBar::closeTabsByZimId() --- src/tabbar.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/tabbar.cpp b/src/tabbar.cpp index 55622cd..eb1ad1a 100644 --- a/src/tabbar.cpp +++ b/src/tabbar.cpp @@ -256,12 +256,13 @@ void TabBar::triggerWebPageAction(QWebEnginePage::WebAction action, ZimView *wid void TabBar::closeTabsByZimId(const QString &id) { - // the last tab is + button, skip it - for (int i = count() - 2 ; i >= 0 ; i--) { + // 0th tab is always (unless this comment becomes outdated by the time you + // read it) the library tab, so iteration could start from 1, however we + // shouldn't try to save CPU cycles at the cost of the code breaking + // should this comment indeed become outdated ;) + for (int i = 0 ; i < realTabCount() ; ++i ) { auto *zv = qobject_cast(mp_stackedWidget->widget(i)); - if (!zv) - continue; - if (zv->getWebView()->zimId() == id) { + if (zv && zv->getWebView()->zimId() == id) { closeTab(i); } }