From f017954314561c058dd7a02119e20f2ba511ba73 Mon Sep 17 00:00:00 2001
From: Adrien Beraud <adrien.beraud@savoirfairelinux.com>
Date: Tue, 5 Sep 2017 15:43:01 +0200
Subject: [PATCH] ringaccount: make value Id distribution non-static

This minor cleanup and performance/memory optimization
replaces the static ID distribution by a type shortcut.
Integer distributions are typically stateless and
are fully optimized-out by the compiler, which was
prevented by the static variable.

Change-Id: I9f75acf57662c7f30404586feea3049d96ce1ca9
Reviewed-by: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
---
 src/ringdht/ringaccount.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/ringdht/ringaccount.cpp b/src/ringdht/ringaccount.cpp
index e5b768c5ec..3c146f6d49 100644
--- a/src/ringdht/ringaccount.cpp
+++ b/src/ringdht/ringaccount.cpp
@@ -238,7 +238,7 @@ static constexpr const char * DEFAULT_TURN_REALM = "ring";
 constexpr const char* const RingAccount::ACCOUNT_TYPE;
 /* constexpr */ const std::pair<uint16_t, uint16_t> RingAccount::DHT_PORT_RANGE {4000, 8888};
 
-static std::uniform_int_distribution<dht::Value::Id> udist;
+using ValueIdDist = std::uniform_int_distribution<dht::Value::Id>;
 
 static const std::string
 stripPrefix(const std::string& toUrl)
@@ -453,7 +453,7 @@ RingAccount::startOutgoingCall(const std::shared_ptr<SIPCall>& call, const std::
             sthis->registerDhtAddress(*ice);
 
             // Next step: sent the ICE data to peer through DHT
-            const dht::Value::Id callvid  = udist(sthis->rand_);
+            const dht::Value::Id callvid  = ValueIdDist()(sthis->rand_);
             const auto callkey = dht::InfoHash::get("callto:" + dev.toString());
             dht::Value val { dht::IceCandidates(callvid, ice->packIceMsg()) };
 
-- 
GitLab