1111
1212#include < folly/Conv.h>
1313#include < folly/Range.h>
14+ #include < folly/container/Reserve.h>
1415
1516#include " mcrouter/CarbonRouterInstanceBase.h"
1617#include " mcrouter/McrouterLogFailure.h"
@@ -319,6 +320,7 @@ McRouteHandleProvider<RouterInfo>::makePool(
319320 jWeights = nullptr ;
320321 }
321322 folly::dynamic jNewWeights = folly::dynamic::array;
323+ auto accessPointsIt = accessPoints_.end ();
322324 for (size_t i = 0 ; i < jservers->size (); ++i) {
323325 const auto & server = jservers->at (i);
324326 checkLogic (
@@ -346,17 +348,21 @@ McRouteHandleProvider<RouterInfo>::makePool(
346348 proxy_.stats ().increment (dest_with_no_failure_domain_count_stat);
347349 }
348350
351+ if (accessPointsIt == accessPoints_.end ()) {
352+ auto expectedSize = jservers->size () * (1 + additionalFanout);
353+ auto [it, inserted] = accessPoints_.try_emplace (name, expectedSize);
354+ accessPointsIt = it;
355+ if (!inserted) {
356+ folly::grow_capacity_by (accessPointsIt->second , expectedSize);
357+ }
358+ }
359+ auto & accessPointsSet = accessPointsIt->second ;
360+ folly::StringPiece nameSp = accessPointsIt->first ;
361+
349362 for (uint32_t idx = 0 ; idx < (1 + additionalFanout); ++idx) {
350363 auto ap = createAccessPoint (
351364 server.stringPiece (), failureDomain, proxy_.router (), *apAttr);
352365
353- auto it = accessPoints_.find (name);
354- if (it == accessPoints_.end ()) {
355- folly::F14FastSet<std::shared_ptr<const AccessPoint>> accessPoints;
356- it = accessPoints_.emplace (name, std::move (accessPoints)).first ;
357- }
358- folly::StringPiece nameSp = it->first ;
359-
360366 if (ap->getProtocol () == mc_thrift_protocol) {
361367 checkLogic (
362368 ap->getSecurityMech () == SecurityMech::NONE ||
@@ -381,7 +387,7 @@ McRouteHandleProvider<RouterInfo>::makePool(
381387 poolTkoTracker,
382388 keepRoutingPrefix,
383389 idx);
384- it-> second .insert (destResult.second );
390+ accessPointsSet .insert (destResult.second );
385391 addDestination (std::move (destResult.first ));
386392 } else {
387393 using Transport = AsyncMcClient;
@@ -398,7 +404,7 @@ McRouteHandleProvider<RouterInfo>::makePool(
398404 poolTkoTracker,
399405 keepRoutingPrefix,
400406 idx);
401- it-> second .insert (destResult.second );
407+ accessPointsSet .insert (destResult.second );
402408 addDestination (std::move (destResult.first ));
403409 }
404410 }
0 commit comments