From: Arnaud Giersch Date: Fri, 4 Dec 2020 10:51:18 +0000 (+0100) Subject: [sonar] Reduce number of nested code blocks. X-Git-Tag: v3.26~51 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/ffc701e216f6a6f08d31fa41613039ebbd1e75f5 [sonar] Reduce number of nested code blocks. Best viewed with 'git show -b' --- diff --git a/src/xbt/xbt_log_layout_format.cpp b/src/xbt/xbt_log_layout_format.cpp index 3ea9ad16f9..c4b118d469 100644 --- a/src/xbt/xbt_log_layout_format.cpp +++ b/src/xbt/xbt_log_layout_format.cpp @@ -77,97 +77,100 @@ static int xbt_log_layout_format_doit(const s_xbt_log_layout_t* l, xbt_log_event auto* q = static_cast(l->data); while (*q != '\0') { - if (*q == '%') { - q++; - do { - switch (*q) { - case '\0': - fprintf(stderr, "Layout format (%s) ending with %%\n", (char*)l->data); - xbt_abort(); - case '%': - *p = '%'; - check_overflow(1); - break; - case 'n': /* platform-dependant line separator; LOG4J compliant */ - *p = '\n'; - check_overflow(1); - break; - case 'e': /* plain space; SimGrid extension */ - *p = ' '; - check_overflow(1); - break; - case '.': /* precision specifier */ - precision = static_cast(strtol(q + 1, &q, 10)); - continue; /* conversion specifier still not found, continue reading */ - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': /* length modifier */ - length = static_cast(strtol(q, &q, 10)); - continue; /* conversion specifier still not found, continue reading */ - case 'c': /* category name; LOG4J compliant - should accept a precision postfix to show the hierarchy */ - show_string(ev->cat->name); - break; - case 'p': /* priority name; LOG4J compliant */ - show_string(xbt_log_priority_names[ev->priority]); - break; - case 'h': /* host name; SimGrid extension */ - show_string(sg_host_self_get_name()); - break; - case 't': /* thread/process name; LOG4J compliant */ - case 'P': /* process name; SimGrid extension */ - show_string(xbt_procname()); - break; - case 'i': /* process PID name; SimGrid extension */ - show_int(xbt_getpid()); - break; - case 'F': /* file name; LOG4J compliant */ - show_string(ev->fileName); - break; - case 'l': { /* location; LOG4J compliant */ - int sz; - set_sz_from_precision(); - int len = snprintf(p, sz, "%s:%d", ev->fileName, ev->lineNum); - check_overflow(std::min(sz, len)); - break; - } - case 'L': /* line number; LOG4J compliant */ - show_int(ev->lineNum); - break; - case 'M': /* method (ie, function) name; LOG4J compliant */ - show_string(ev->functionName); - break; - case 'd': /* date; LOG4J compliant */ - case 'r': /* application age; LOG4J compliant */ - show_double(simgrid_get_clock()); - break; - case 'm': { /* user-provided message; LOG4J compliant */ - int sz; - set_sz_from_precision(); - va_list ap; - va_copy(ap, ev->ap); - int len = vsnprintf(p, sz, msg_fmt, ap); - va_end(ap); - check_overflow(std::min(sz, len)); - break; - } - default: - fprintf(stderr, ERRMSG, *q, (char*)l->data); - xbt_abort(); - } - break; /* done, continue normally */ - } while (true); - } else { + if (*q != '%') { *p = *q; check_overflow(1); + q++; + continue; } + + // *q == '%' + q++; + do { + switch (*q) { + case '\0': + fprintf(stderr, "Layout format (%s) ending with %%\n", (char*)l->data); + xbt_abort(); + case '%': + *p = '%'; + check_overflow(1); + break; + case 'n': /* platform-dependant line separator; LOG4J compliant */ + *p = '\n'; + check_overflow(1); + break; + case 'e': /* plain space; SimGrid extension */ + *p = ' '; + check_overflow(1); + break; + case '.': /* precision specifier */ + precision = static_cast(strtol(q + 1, &q, 10)); + continue; /* conversion specifier still not found, continue reading */ + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': /* length modifier */ + length = static_cast(strtol(q, &q, 10)); + continue; /* conversion specifier still not found, continue reading */ + case 'c': /* category name; LOG4J compliant + should accept a precision postfix to show the hierarchy */ + show_string(ev->cat->name); + break; + case 'p': /* priority name; LOG4J compliant */ + show_string(xbt_log_priority_names[ev->priority]); + break; + case 'h': /* host name; SimGrid extension */ + show_string(sg_host_self_get_name()); + break; + case 't': /* thread/process name; LOG4J compliant */ + case 'P': /* process name; SimGrid extension */ + show_string(xbt_procname()); + break; + case 'i': /* process PID name; SimGrid extension */ + show_int(xbt_getpid()); + break; + case 'F': /* file name; LOG4J compliant */ + show_string(ev->fileName); + break; + case 'l': { /* location; LOG4J compliant */ + int sz; + set_sz_from_precision(); + int len = snprintf(p, sz, "%s:%d", ev->fileName, ev->lineNum); + check_overflow(std::min(sz, len)); + break; + } + case 'L': /* line number; LOG4J compliant */ + show_int(ev->lineNum); + break; + case 'M': /* method (ie, function) name; LOG4J compliant */ + show_string(ev->functionName); + break; + case 'd': /* date; LOG4J compliant */ + case 'r': /* application age; LOG4J compliant */ + show_double(simgrid_get_clock()); + break; + case 'm': { /* user-provided message; LOG4J compliant */ + int sz; + set_sz_from_precision(); + va_list ap; + va_copy(ap, ev->ap); + int len = vsnprintf(p, sz, msg_fmt, ap); + va_end(ap); + check_overflow(std::min(sz, len)); + break; + } + default: + fprintf(stderr, ERRMSG, *q, (char*)l->data); + xbt_abort(); + } + break; /* done, continue normally */ + } while (true); q++; } *p = '\0'; diff --git a/src/xbt/xbt_replay.cpp b/src/xbt/xbt_replay.cpp index c75acf1028..8decf15f26 100644 --- a/src/xbt/xbt_replay.cpp +++ b/src/xbt/xbt_replay.cpp @@ -70,20 +70,19 @@ static ReplayAction* get_action(const char* name) // if it's for me, I'm done std::string evtname = action->front(); - if (evtname.compare(name) == 0) { + if (evtname.compare(name) == 0) return action; - } else { - // Else, I have to store it for the relevant colleague - std::queue* otherqueue = nullptr; - auto act = action_queues.find(evtname); - if (act != action_queues.end()) { - otherqueue = act->second; - } else { // Damn. Create the queue of that guy - otherqueue = new std::queue(); - action_queues.insert({evtname, otherqueue}); - } - otherqueue->push(action); + + // Else, I have to store it for the relevant colleague + std::queue* otherqueue = nullptr; + auto act = action_queues.find(evtname); + if (act != action_queues.end()) { + otherqueue = act->second; + } else { // Damn. Create the queue of that guy + otherqueue = new std::queue(); + action_queues.insert({evtname, otherqueue}); } + otherqueue->push(action); } // end of file reached while searching in vain for more work } else { diff --git a/src/xbt/xbt_str.cpp b/src/xbt/xbt_str.cpp index dfd3d6b95c..78a21c50f7 100644 --- a/src/xbt/xbt_str.cpp +++ b/src/xbt/xbt_str.cpp @@ -136,26 +136,26 @@ xbt_dynar_t xbt_str_split_quoted_in_place(char *s) { } if (in_simple_quote || in_double_quote) { end++; - } else { - if (*end == '\0') - done = 1; - - *end = '\0'; - if (ctn) { - /* Found a separator. Push the string if contains something */ - xbt_dynar_push(res, &beg); - } - ctn = 0; - - if (done) - break; - - beg = ++end; - /* trim within the string, manually to speed things up */ - while (*beg == ' ') - beg++; - end = beg; + break; + } + if (*end == '\0') + done = 1; + + *end = '\0'; + if (ctn) { + /* Found a separator. Push the string if contains something */ + xbt_dynar_push(res, &beg); } + ctn = 0; + + if (done) + break; + + beg = ++end; + /* trim within the string, manually to speed things up */ + while (*beg == ' ') + beg++; + end = beg; break; default: ctn = 1; diff --git a/teshsuite/simdag/flatifier/flatifier.cpp b/teshsuite/simdag/flatifier/flatifier.cpp index 40bb84aa09..b9036e2737 100644 --- a/teshsuite/simdag/flatifier/flatifier.cpp +++ b/teshsuite/simdag/flatifier/flatifier.cpp @@ -130,48 +130,48 @@ static void dump_routes() std::vector route; simgrid::kernel::routing::NetPoint* dst = host2->get_netpoint(); simgrid::kernel::routing::NetZoneImpl::get_global_route(src, dst, route, nullptr); - if (not route.empty()) { - std::printf(" \n ", host1->get_cname(), host2->get_cname()); - for (auto const& link : route) - std::printf("", link->get_cname()); - std::printf("\n \n"); - } + if (route.empty()) + continue; + std::printf(" \n ", host1->get_cname(), host2->get_cname()); + for (auto const& link : route) + std::printf("", link->get_cname()); + std::printf("\n \n"); } for (auto const& dst : netpoints) { // to router - if (dst->is_router()) { - std::printf(" \n ", host1->get_cname(), dst->get_cname()); - std::vector route; - simgrid::kernel::routing::NetZoneImpl::get_global_route(src, dst, route, nullptr); - for (auto const& link : route) - std::printf("", link->get_cname()); - std::printf("\n \n"); - } + if (not dst->is_router()) + continue; + std::printf(" \n ", host1->get_cname(), dst->get_cname()); + std::vector route; + simgrid::kernel::routing::NetZoneImpl::get_global_route(src, dst, route, nullptr); + for (auto const& link : route) + std::printf("", link->get_cname()); + std::printf("\n \n"); } } for (auto const& value1 : netpoints) { // Routes from router - if (value1->is_router()) { - for (auto const& value2 : netpoints) { // to router - if (value2->is_router()) { - std::printf(" \n ", value1->get_cname(), value2->get_cname()); - std::vector route; - simgrid::kernel::routing::NetZoneImpl::get_global_route(value1, value2, route, nullptr); - for (auto const& link : route) - std::printf("", link->get_cname()); - std::printf("\n \n"); - } - } - for (unsigned int it_dst = 0; it_dst < totalHosts; it_dst++) { // Routes to host - const simgrid::s4u::Host* host2 = hosts[it_dst]; - std::printf(" \n ", value1->get_cname(), host2->get_cname()); - std::vector route; - simgrid::kernel::routing::NetPoint* netcardDst = host2->get_netpoint(); - simgrid::kernel::routing::NetZoneImpl::get_global_route(value1, netcardDst, route, nullptr); - for (auto const& link : route) - std::printf("", link->get_cname()); - std::printf("\n \n"); - } + if (not value1->is_router()) + continue; + for (auto const& value2 : netpoints) { // to router + if (not value2->is_router()) + continue; + std::printf(" \n ", value1->get_cname(), value2->get_cname()); + std::vector route; + simgrid::kernel::routing::NetZoneImpl::get_global_route(value1, value2, route, nullptr); + for (auto const& link : route) + std::printf("", link->get_cname()); + std::printf("\n \n"); + } + for (unsigned int it_dst = 0; it_dst < totalHosts; it_dst++) { // Routes to host + const simgrid::s4u::Host* host2 = hosts[it_dst]; + std::printf(" \n ", value1->get_cname(), host2->get_cname()); + std::vector route; + simgrid::kernel::routing::NetPoint* netcardDst = host2->get_netpoint(); + simgrid::kernel::routing::NetZoneImpl::get_global_route(value1, netcardDst, route, nullptr); + for (auto const& link : route) + std::printf("", link->get_cname()); + std::printf("\n \n"); } } xbt_free(hosts);