Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Put the loop right (easier to read and more efficient when building string).
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 8 Jan 2020 20:21:16 +0000 (21:21 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 9 Jan 2020 10:46:03 +0000 (11:46 +0100)
examples/s4u/app-bittorrent/s4u-peer.cpp

index 9c6706d..2670cd7 100644 (file)
@@ -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;
 }