From: Arnaud Giersch Date: Wed, 8 Jan 2020 20:21:16 +0000 (+0100) Subject: Put the loop right (easier to read and more efficient when building string). X-Git-Tag: v3.25~131 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/28f286afde4bb622772b563a6589e5e0ed9bd3c0?ds=sidebyside Put the loop right (easier to read and more efficient when building string). --- diff --git a/examples/s4u/app-bittorrent/s4u-peer.cpp b/examples/s4u/app-bittorrent/s4u-peer.cpp index 9c6706d191..2670cd7c51 100644 --- a/examples/s4u/app-bittorrent/s4u-peer.cpp +++ b/examples/s4u/app-bittorrent/s4u-peer.cpp @@ -160,9 +160,9 @@ void Peer::sendRequestTo(Connection* remote_peer, unsigned int piece) std::string Peer::getStatus() { - std::string res = std::string(""); - for (int i = FILE_PIECES - 1; i >= 0; i--) - res = std::string((bitfield_ & (1U << i)) ? "1" : "0") + res; + std::string res; + for (unsigned i = 0; i < FILE_PIECES; i++) + res += (bitfield_ & (1U << i)) ? '1' : '0'; return res; }