From e3e4c4433e484e45e5112d35e6ded5714bdaddee Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 17 Mar 2021 11:08:05 +0100 Subject: [PATCH] Misc sonar smells. --- src/mc/udpor_global.cpp | 10 ++++------ src/mc/udpor_global.hpp | 10 +++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/mc/udpor_global.cpp b/src/mc/udpor_global.cpp index d4bb5193b0..bd38ee7b74 100644 --- a/src/mc/udpor_global.cpp +++ b/src/mc/udpor_global.cpp @@ -5,13 +5,14 @@ #include "udpor_global.hpp" #include "xbt/log.h" +#include XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_udpor_global, mc, "udpor_global"); namespace simgrid { namespace mc { -EventSet EvtSetTools::makeUnion(EventSet s1, EventSet s2) +EventSet EvtSetTools::makeUnion(const EventSet& s1, const EventSet& s2) { EventSet res = s1; for (auto evt : s2) @@ -25,12 +26,9 @@ void EvtSetTools::pushBack(EventSet& events, UnfoldingEvent* e) events.push_back(e); } -bool EvtSetTools::contains(const EventSet events, const UnfoldingEvent* e) +bool EvtSetTools::contains(const EventSet& events, const UnfoldingEvent* e) { - for (auto evt : events) - if (*evt == *e) - return true; - return false; + return std::any_of(events.begin(), events.end(), [e](const UnfoldingEvent* evt) { return *evt == *e; }); } } // namespace mc diff --git a/src/mc/udpor_global.hpp b/src/mc/udpor_global.hpp index 2c8b7a123d..bc01589125 100644 --- a/src/mc/udpor_global.hpp +++ b/src/mc/udpor_global.hpp @@ -17,12 +17,12 @@ using EventSet = std::deque; class EvtSetTools { public: - static bool contains(const EventSet events, const UnfoldingEvent* e); + static bool contains(const EventSet& events, const UnfoldingEvent* e); static UnfoldingEvent* find(const EventSet events, const UnfoldingEvent* e); static void subtract(EventSet& events, EventSet const& otherSet); static bool depends(EventSet const& events, EventSet const& otherSet); static bool isEmptyIntersection(EventSet evtS1, EventSet evtS2); - static EventSet makeUnion(EventSet s1, EventSet s2); + static EventSet makeUnion(const EventSet& s1, const EventSet& s2); static void pushBack(EventSet& events, UnfoldingEvent* e); static void remove(EventSet& events, UnfoldingEvent* e); static EventSet minus(EventSet events, UnfoldingEvent* e); @@ -58,7 +58,6 @@ public: class UnfoldingEvent { public: - int id = -1; EventSet causes; // used to store directed ancestors of event e UnfoldingEvent(unsigned int nb_events, std::string const& trans_tag, EventSet const& causes, int sid = -1); UnfoldingEvent(const UnfoldingEvent&) = default; @@ -76,8 +75,8 @@ public: bool isImmediateConflict1(UnfoldingEvent* evt, UnfoldingEvent* otherEvt) const; bool conflictWithConfig(UnfoldingEvent* event, Configuration const& config) const; - /* TODO: implement */ - bool operator==(const UnfoldingEvent& other) const { return false; }; + /* TODO: implement */ + bool operator==(const UnfoldingEvent&) const { return false; }; void print() const; inline int get_state_id() const { return state_id; } @@ -87,6 +86,7 @@ public: inline void set_transition_tag(std::string const& tr_tag) { transition_tag = tr_tag; } private: + int id = -1; int state_id{-1}; std::string transition_tag{""}; // The tag of the last transition that lead to creating the event bool transition_is_IReceive(const UnfoldingEvent* testedEvt, const UnfoldingEvent* SdRcEvt) const; -- 2.20.1