Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Put the loop right (easier to read and more efficient when building string).
[simgrid.git] / 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;
 }