From 28f286afde4bb622772b563a6589e5e0ed9bd3c0 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 8 Jan 2020 21:21:16 +0100 Subject: [PATCH] Put the loop right (easier to read and more efficient when building string). --- examples/s4u/app-bittorrent/s4u-peer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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; } -- 2.30.2