From cc7b7992ff4435b177d08072c52956238167d939 Mon Sep 17 00:00:00 2001 From: Paolo Molaro Date: Tue, 5 Nov 2013 17:37:08 +0100 Subject: [PATCH] Reduce contention and unnecessary checks at each lookup, part of xambug #14644. --- mcs/class/System/System.Net/ServicePointManager.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mcs/class/System/System.Net/ServicePointManager.cs b/mcs/class/System/System.Net/ServicePointManager.cs index a6d456293e6..27e9893a80a 100644 --- a/mcs/class/System/System.Net/ServicePointManager.cs +++ b/mcs/class/System/System.Net/ServicePointManager.cs @@ -326,7 +326,8 @@ namespace System.Net if (address == null) throw new ArgumentNullException ("address"); - RecycleServicePoints (); + if ((servicePoints.Count % 4) == 0) + RecycleServicePoints (); var origAddress = new Uri (address.Scheme + "://" + address.Authority); @@ -346,8 +347,8 @@ namespace System.Net address = new Uri (address.Scheme + "://" + address.Authority); ServicePoint sp = null; + SPKey key = new SPKey (origAddress, usesProxy ? address : null, useConnect); lock (servicePoints) { - SPKey key = new SPKey (origAddress, usesProxy ? address : null, useConnect); sp = servicePoints [key] as ServicePoint; if (sp != null) return sp; -- 2.25.1