]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Replace all uses of core::list with std::list (#12313)
authorparadust7 <102263465+paradust7@users.noreply.github.com>
Sat, 21 May 2022 22:11:59 +0000 (15:11 -0700)
committerGitHub <noreply@github.com>
Sat, 21 May 2022 22:11:59 +0000 (00:11 +0200)
16 files changed:
src/gui/guiConfirmRegistration.cpp
src/gui/guiConfirmRegistration.h
src/gui/guiFormSpecMenu.cpp
src/gui/guiFormSpecMenu.h
src/gui/guiKeyChangeMenu.cpp
src/gui/guiKeyChangeMenu.h
src/gui/guiPasswordChange.cpp
src/gui/guiPasswordChange.h
src/gui/guiPathSelectMenu.cpp
src/gui/guiScrollContainer.cpp
src/gui/guiVolumeChange.cpp
src/gui/guiVolumeChange.h
src/gui/mainmenumanager.h
src/gui/modalMenu.cpp
src/gui/modalMenu.h
src/unittest/test.cpp

index b8887a4af1c5cc745df89480cb0d39c53f410220..c5aa9c85e209b6dc50028dd5ee4505fbedd8ae22 100644 (file)
@@ -54,25 +54,10 @@ GUIConfirmRegistration::GUIConfirmRegistration(gui::IGUIEnvironment *env,
 #endif
 }
 
-GUIConfirmRegistration::~GUIConfirmRegistration()
-{
-       removeChildren();
-}
-
-void GUIConfirmRegistration::removeChildren()
-{
-       const core::list<gui::IGUIElement *> &children = getChildren();
-       core::list<gui::IGUIElement *> children_copy;
-       for (gui::IGUIElement *i : children)
-               children_copy.push_back(i);
-       for (gui::IGUIElement *i : children_copy)
-               i->remove();
-}
-
 void GUIConfirmRegistration::regenerateGui(v2u32 screensize)
 {
        acceptInput();
-       removeChildren();
+       removeAllChildren();
 
        /*
                Calculate new sizes and positions
index d8387201d46d88d2a0aa7e97997873c4603611e6..fb215775639da28bd6493e82f6fe8a73b29fb805 100644 (file)
@@ -34,9 +34,6 @@ class GUIConfirmRegistration : public GUIModalMenu
                        s32 id, IMenuManager *menumgr, Client *client,
                        const std::string &playername, const std::string &password,
                        bool *aborted, ISimpleTextureSource *tsrc);
-       ~GUIConfirmRegistration();
-
-       void removeChildren();
        /*
                Remove and re-add (or reposition) stuff
        */
index f3570ccaf099f52cb8f653a37e3c102dc9bbb78b..422d6da16289530de4ee6858dbf7347dfb92bef0 100644 (file)
@@ -127,7 +127,8 @@ GUIFormSpecMenu::GUIFormSpecMenu(JoystickController *joystick,
 
 GUIFormSpecMenu::~GUIFormSpecMenu()
 {
-       removeChildren();
+       removeAllChildren();
+       removeTooltip();
 
        for (auto &table_it : m_tables)
                table_it.second->drop();
@@ -174,14 +175,8 @@ void GUIFormSpecMenu::create(GUIFormSpecMenu *&cur_formspec, Client *client,
        }
 }
 
-void GUIFormSpecMenu::removeChildren()
+void GUIFormSpecMenu::removeTooltip()
 {
-       const core::list<gui::IGUIElement*> &children = getChildren();
-
-       while (!children.empty()) {
-               (*children.getLast())->remove();
-       }
-
        if (m_tooltip_element) {
                m_tooltip_element->remove();
                m_tooltip_element->drop();
@@ -199,16 +194,7 @@ void GUIFormSpecMenu::setInitialFocus()
        // 5. first focusable (not statictext, not tabheader)
        // 6. first child element
 
-       core::list<gui::IGUIElement*> children = getChildren();
-
-       // in case "children" contains any NULL elements, remove them
-       for (core::list<gui::IGUIElement*>::Iterator it = children.begin();
-                       it != children.end();) {
-               if (*it)
-                       ++it;
-               else
-                       it = children.erase(it);
-       }
+       const auto& children = getChildren();
 
        // 1. first empty editbox
        for (gui::IGUIElement *it : children) {
@@ -236,8 +222,7 @@ void GUIFormSpecMenu::setInitialFocus()
        }
 
        // 4. last button
-       for (core::list<gui::IGUIElement*>::Iterator it = children.getLast();
-                       it != children.end(); --it) {
+       for (auto it = children.rbegin(); it != children.rend(); ++it) {
                if ((*it)->getType() == gui::EGUIET_BUTTON) {
                        Environment->setFocus(*it);
                        return;
@@ -257,7 +242,7 @@ void GUIFormSpecMenu::setInitialFocus()
        if (children.empty())
                Environment->setFocus(this);
        else
-               Environment->setFocus(*(children.begin()));
+               Environment->setFocus(children.front());
 }
 
 GUITable* GUIFormSpecMenu::getTable(const std::string &tablename)
@@ -3045,7 +3030,8 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
        }
 
        // Remove children
-       removeChildren();
+       removeAllChildren();
+       removeTooltip();
 
        for (auto &table_it : m_tables)
                table_it.second->drop();
@@ -3341,7 +3327,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
        pos_offset = v2f32();
 
        // used for formspec versions < 3
-       core::list<IGUIElement *>::Iterator legacy_sort_start = Children.getLast();
+       std::list<IGUIElement *>::iterator legacy_sort_start = std::prev(Children.end()); // last element
 
        if (enable_prepends) {
                // Backup the coordinates so that prepends can use the coordinates of choice.
@@ -3356,7 +3342,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
                // legacy sorting for formspec versions < 3
                if (m_formspec_version >= 3)
                        // prepends do not need to be reordered
-                       legacy_sort_start = Children.getLast();
+                       legacy_sort_start = std::prev(Children.end()); // last element
                else if (version_backup >= 3)
                        // only prepends elements have to be reordered
                        legacySortElements(legacy_sort_start);
@@ -3437,7 +3423,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
        }
 }
 
-void GUIFormSpecMenu::legacySortElements(core::list<IGUIElement *>::Iterator from)
+void GUIFormSpecMenu::legacySortElements(std::list<IGUIElement *>::iterator from)
 {
        /*
                Draw order for formspec_version <= 2:
@@ -3454,17 +3440,16 @@ void GUIFormSpecMenu::legacySortElements(core::list<IGUIElement *>::Iterator fro
        if (from == Children.end())
                from = Children.begin();
        else
-               from++;
+               ++from;
 
-       core::list<IGUIElement *>::Iterator to = Children.end();
+       std::list<IGUIElement *>::iterator to = Children.end();
        // 1: Copy into a sortable container
-       std::vector<IGUIElement *> elements;
-       for (auto it = from; it != to; ++it)
-               elements.emplace_back(*it);
+       std::vector<IGUIElement *> elements(from, to);
 
        // 2: Sort the container
        std::stable_sort(elements.begin(), elements.end(),
                        [this] (const IGUIElement *a, const IGUIElement *b) -> bool {
+               // TODO: getSpecByID is a linear search. It should made O(1), or cached here.
                const FieldSpec *spec_a = getSpecByID(a->getID());
                const FieldSpec *spec_b = getSpecByID(b->getID());
                return spec_a && spec_b &&
@@ -3472,10 +3457,7 @@ void GUIFormSpecMenu::legacySortElements(core::list<IGUIElement *>::Iterator fro
        });
 
        // 3: Re-assign the pointers
-       for (auto e : elements) {
-               *from = e;
-               from++;
-       }
+       reorderChildren(from, to, elements);
 }
 
 #ifdef __ANDROID__
@@ -3600,12 +3582,11 @@ void GUIFormSpecMenu::drawMenu()
        /*
                This is where all the drawing happens.
        */
-       core::list<IGUIElement*>::Iterator it = Children.begin();
-       for (; it != Children.end(); ++it)
-               if ((*it)->isNotClipped() ||
+       for (auto child : Children)
+               if (child->isNotClipped() ||
                                AbsoluteClippingRect.isRectCollided(
-                                               (*it)->getAbsolutePosition()))
-                       (*it)->draw();
+                                               child->getAbsolutePosition()))
+                       child->draw();
 
        for (gui::IGUIElement *e : m_clickthrough_elements)
                e->setVisible(false);
index 3fedb3b78cd550438a6a8bf9cc5b355c90d6ee95..a584456db23c680b7fe6264b66592fb5ef508c5b 100644 (file)
@@ -212,7 +212,7 @@ class GUIFormSpecMenu : public GUIModalMenu
                m_lockscreensize = basescreensize;
        }
 
-       void removeChildren();
+       void removeTooltip();
        void setInitialFocus();
 
        void setFocus(const std::string &elementname)
@@ -467,7 +467,7 @@ class GUIFormSpecMenu : public GUIModalMenu
         * types were drawn before others.
         * This function sorts the elements in the old order for backwards compatibility.
         */
-       void legacySortElements(core::list<IGUIElement *>::Iterator from);
+       void legacySortElements(std::list<IGUIElement *>::iterator from);
 
        int m_btn_height;
        gui::IGUIFont *m_font = nullptr;
index ada6280f689eece655f5e6cc38ddb665b18ab049..021f5f0a9cf5b5422f0357bf5b8ae336a774d40a 100644 (file)
@@ -93,7 +93,8 @@ GUIKeyChangeMenu::GUIKeyChangeMenu(gui::IGUIEnvironment* env,
 
 GUIKeyChangeMenu::~GUIKeyChangeMenu()
 {
-       removeChildren();
+       removeAllChildren();
+       key_used_text = nullptr;
 
        for (key_setting *ks : key_settings) {
                delete[] ks->button_name;
@@ -102,23 +103,10 @@ GUIKeyChangeMenu::~GUIKeyChangeMenu()
        key_settings.clear();
 }
 
-void GUIKeyChangeMenu::removeChildren()
-{
-       const core::list<gui::IGUIElement*> &children = getChildren();
-       core::list<gui::IGUIElement*> children_copy;
-       for (gui::IGUIElement*i : children) {
-               children_copy.push_back(i);
-       }
-
-       for (gui::IGUIElement *i : children_copy) {
-               i->remove();
-       }
-       key_used_text = nullptr;
-}
-
 void GUIKeyChangeMenu::regenerateGui(v2u32 screensize)
 {
-       removeChildren();
+       removeAllChildren();
+       key_used_text = nullptr;
 
        const float s = m_gui_scale;
        DesiredRect = core::rect<s32>(
index 1c0f40247fee1f008cf7b85428259469d476a125..84a898774ab114a332222ffdc1226802101f4681 100644 (file)
@@ -46,7 +46,6 @@ class GUIKeyChangeMenu : public GUIModalMenu
                        IMenuManager *menumgr, ISimpleTextureSource *tsrc);
        ~GUIKeyChangeMenu();
 
-       void removeChildren();
        /*
         Remove and re-add (or reposition) stuff
         */
index c983260f6a90807f6ddecbeeb599c7ffcb3fd5b4..c39df176ba14c2aab3a42f1d0a5674d12a7b0d3c 100644 (file)
@@ -51,23 +51,6 @@ GUIPasswordChange::GUIPasswordChange(gui::IGUIEnvironment* env,
 {
 }
 
-GUIPasswordChange::~GUIPasswordChange()
-{
-       removeChildren();
-}
-
-void GUIPasswordChange::removeChildren()
-{
-       const core::list<gui::IGUIElement *> &children = getChildren();
-       core::list<gui::IGUIElement *> children_copy;
-       for (gui::IGUIElement *i : children) {
-               children_copy.push_back(i);
-       }
-
-       for (gui::IGUIElement *i : children_copy) {
-               i->remove();
-       }
-}
 void GUIPasswordChange::regenerateGui(v2u32 screensize)
 {
        /*
@@ -78,7 +61,7 @@ void GUIPasswordChange::regenerateGui(v2u32 screensize)
        /*
                Remove stuff
        */
-       removeChildren();
+       removeAllChildren();
 
        /*
                Calculate new sizes and positions
index 7141100c08593a6eaf305c1fcc8f26bec4c72a55..452702add3b7afa0e987971a0d48f0b41c9bde70 100644 (file)
@@ -31,9 +31,7 @@ class GUIPasswordChange : public GUIModalMenu
        GUIPasswordChange(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id,
                        IMenuManager *menumgr, Client *client,
                        ISimpleTextureSource *tsrc);
-       ~GUIPasswordChange();
 
-       void removeChildren();
        /*
                Remove and re-add (or reposition) stuff
        */
index 489927a11d822989a6332caba3225169d82f1463..9c63e06b5116504a9ad9810a4dba73ae043b7674 100644 (file)
@@ -32,13 +32,12 @@ GUIFileSelectMenu::GUIFileSelectMenu(gui::IGUIEnvironment* env,
 
 GUIFileSelectMenu::~GUIFileSelectMenu()
 {
-       removeChildren();
        setlocale(LC_NUMERIC, "C");
 }
 
 void GUIFileSelectMenu::regenerateGui(v2u32 screensize)
 {
-       removeChildren();
+       removeAllChildren();
        m_fileOpenDialog = 0;
 
        core::dimension2du size(600 * m_gui_scale, 400 * m_gui_scale);
index 0fe4c41bdea1b42cb94d208cf66100385a73f191..2d71f3453d4e70b996e6c93f0d256c3c8dcf475b 100644 (file)
@@ -59,12 +59,11 @@ bool GUIScrollContainer::OnEvent(const SEvent &event)
 void GUIScrollContainer::draw()
 {
        if (isVisible()) {
-               core::list<IGUIElement *>::Iterator it = Children.begin();
-               for (; it != Children.end(); ++it)
-                       if ((*it)->isNotClipped() ||
+               for (auto child : Children)
+                       if (child->isNotClipped() ||
                                        AbsoluteClippingRect.isRectCollided(
-                                                       (*it)->getAbsolutePosition()))
-                               (*it)->draw();
+                                                       child->getAbsolutePosition()))
+                               child->draw();
        }
 }
 
index 61ab758a11425c5d0e35b6afcf0bc87e7056d32b..0f6f43fe9b6c4f57c7a36e03d8917b4019262af9 100644 (file)
@@ -45,32 +45,12 @@ GUIVolumeChange::GUIVolumeChange(gui::IGUIEnvironment* env,
 {
 }
 
-GUIVolumeChange::~GUIVolumeChange()
-{
-       removeChildren();
-}
-
-void GUIVolumeChange::removeChildren()
-{
-       if (gui::IGUIElement *e = getElementFromId(ID_soundText))
-               e->remove();
-
-       if (gui::IGUIElement *e = getElementFromId(ID_soundExitButton))
-               e->remove();
-
-       if (gui::IGUIElement *e = getElementFromId(ID_soundSlider))
-               e->remove();
-
-       if (gui::IGUIElement *e = getElementFromId(ID_soundMuteButton))
-               e->remove();
-}
-
 void GUIVolumeChange::regenerateGui(v2u32 screensize)
 {
        /*
                Remove stuff
        */
-       removeChildren();
+       removeAllChildren();
        /*
                Calculate new sizes and positions
        */
index 466e17f9d90a29c27f3633471c763dbfc732f5e0..ccdaca00b908a56958339feb553753f6fa375bb2 100644 (file)
@@ -31,9 +31,6 @@ class GUIVolumeChange : public GUIModalMenu
        GUIVolumeChange(gui::IGUIEnvironment* env,
                        gui::IGUIElement* parent, s32 id,
                        IMenuManager *menumgr, ISimpleTextureSource *tsrc);
-       ~GUIVolumeChange();
-
-       void removeChildren();
        /*
                Remove and re-add (or reposition) stuff
        */
index 102492255b78860f2baf11db7ea6ad5ed783b68d..76d3573405b0c1790f85f4a5e1f27025b5eac9be 100644 (file)
@@ -64,10 +64,6 @@ class MainMenuManager : public IMenuManager
                // Remove all entries if there are duplicates
                m_stack.remove(menu);
 
-               /*core::list<GUIModalMenu*>::Iterator i = m_stack.getLast();
-               assert(*i == menu);
-               m_stack.erase(i);*/
-
                if(!m_stack.empty())
                        m_stack.back()->setVisible(true);
        }
index 56a5d2cb9ed39796b76ca2a58adb4b7bc9fceca1..d27f63d9404fc9a7ea9cbe6a12d84c7abd1df3ee 100644 (file)
@@ -108,19 +108,6 @@ void GUIModalMenu::quitMenu()
 #endif
 }
 
-void GUIModalMenu::removeChildren()
-{
-       const core::list<gui::IGUIElement *> &children = getChildren();
-       core::list<gui::IGUIElement *> children_copy;
-       for (gui::IGUIElement *i : children) {
-               children_copy.push_back(i);
-       }
-
-       for (gui::IGUIElement *i : children_copy) {
-               i->remove();
-       }
-}
-
 // clang-format off
 bool GUIModalMenu::DoubleClickDetection(const SEvent &event)
 {
index 06e78f06b465ca2fdd100857b769e269c622d24f..e37c41533636f68a89a930b6e52bf5736a41cc49 100644 (file)
@@ -47,7 +47,6 @@ class GUIModalMenu : public gui::IGUIElement
        bool canTakeFocus(gui::IGUIElement *e);
        void draw();
        void quitMenu();
-       void removeChildren();
 
        virtual void regenerateGui(v2u32 screensize) = 0;
        virtual void drawMenu() = 0;
index 676fe8e13ed3070787ffa06f5b214c6203bcee97..af30c209dba101c77dedf12fe3d05ef37f508a7f 100644 (file)
@@ -360,7 +360,7 @@ struct TestMapBlock: public TestBase
 
                MapNode node;
                bool position_valid;
-               core::list<v3s16> validity_exceptions;
+               std::list<v3s16> validity_exceptions;
 
                TC()
                {
@@ -371,7 +371,7 @@ struct TestMapBlock: public TestBase
                {
                        //return position_valid ^ (p==position_valid_exception);
                        bool exception = false;
-                       for(core::list<v3s16>::Iterator i=validity_exceptions.begin();
+                       for(std::list<v3s16>::iterator i=validity_exceptions.begin();
                                        i != validity_exceptions.end(); i++)
                        {
                                if(p == *i)