summaryrefslogtreecommitdiff
path: root/cs/src/Ice/Reference.cs
diff options
context:
space:
mode:
Diffstat (limited to 'cs/src/Ice/Reference.cs')
-rw-r--r--cs/src/Ice/Reference.cs77
1 files changed, 66 insertions, 11 deletions
diff --git a/cs/src/Ice/Reference.cs b/cs/src/Ice/Reference.cs
index 7d5759f2838..c52bfa90a6e 100644
--- a/cs/src/Ice/Reference.cs
+++ b/cs/src/Ice/Reference.cs
@@ -1360,7 +1360,7 @@ namespace IceInternal
private EndpointI[] filterEndpoints(EndpointI[] allEndpoints)
{
- ArrayList endpoints = new ArrayList();
+ List<EndpointI> endpoints = new List<EndpointI>();
//
// Filter out unknown endpoints.
@@ -1385,7 +1385,7 @@ namespace IceInternal
//
// Filter out datagram endpoints.
//
- ArrayList tmp = new ArrayList();
+ List<EndpointI> tmp = new List<EndpointI>();
foreach(EndpointI endpoint in endpoints)
{
if(!endpoint.datagram())
@@ -1403,7 +1403,7 @@ namespace IceInternal
//
// Filter out non-datagram endpoints.
//
- ArrayList tmp = new ArrayList();
+ List<EndpointI> tmp = new List<EndpointI>();
foreach(EndpointI endpoint in endpoints)
{
if(endpoint.datagram())
@@ -1431,7 +1431,7 @@ namespace IceInternal
Debug.Assert(r >= i && r < endpoints.Count);
if(r != i)
{
- object tmp = endpoints[i];
+ EndpointI tmp = endpoints[i];
endpoints[i] = endpoints[r];
endpoints[r] = tmp;
}
@@ -1461,7 +1461,7 @@ namespace IceInternal
DefaultsAndOverrides overrides = getInstance().defaultsAndOverrides();
if(overrides.overrideSecure ? overrides.overrideSecureValue : getSecure())
{
- ArrayList tmp = new ArrayList();
+ List<EndpointI> tmp = new List<EndpointI>();
foreach(EndpointI endpoint in endpoints)
{
if(endpoint.secure())
@@ -1473,11 +1473,11 @@ namespace IceInternal
}
else if(getPreferSecure())
{
- IceUtilInternal.Arrays.Sort(ref endpoints, _preferSecureEndpointComparator);
+ Sort(ref endpoints, _preferSecureEndpointComparator);
}
else
{
- IceUtilInternal.Arrays.Sort(ref endpoints, _preferNonSecureEndpointComparator);
+ Sort(ref endpoints, _preferNonSecureEndpointComparator);
}
EndpointI[] arr = new EndpointI[endpoints.Count];
@@ -1642,17 +1642,15 @@ namespace IceInternal
}
}
- private class EndpointComparator : IComparer
+ private class EndpointComparator : IComparer<IceInternal.EndpointI>
{
public EndpointComparator(bool preferSecure)
{
_preferSecure = preferSecure;
}
- public int Compare(object l, object r)
+ public int Compare(IceInternal.EndpointI le, IceInternal.EndpointI re)
{
- IceInternal.EndpointI le = (IceInternal.EndpointI)l;
- IceInternal.EndpointI re = (IceInternal.EndpointI)r;
bool ls = le.secure();
bool rs = re.secure();
if((ls && rs) || (!ls && !rs))
@@ -1685,6 +1683,63 @@ namespace IceInternal
private bool _preferSecure;
}
+
+ private static void Sort(ref List<IceInternal.EndpointI> array, IComparer<IceInternal.EndpointI> comparator)
+ {
+ //
+ // This Sort method implements the merge sort algorithm
+ // which is a stable sort (unlike the Sort method of the
+ // System.Collections.ArrayList which is unstable).
+ //
+ Sort1(ref array, 0, array.Count, comparator);
+ }
+
+ private static void Sort1(ref List<IceInternal.EndpointI> array, int begin, int end, IComparer<IceInternal.EndpointI> comparator)
+ {
+ int mid;
+ if(end - begin <= 1)
+ {
+ return;
+ }
+
+ mid = (begin + end) / 2;
+ Sort1(ref array, begin, mid, comparator);
+ Sort1(ref array, mid, end, comparator);
+ Merge(ref array, begin, mid, end, comparator);
+ }
+
+ private static void Merge(ref List<IceInternal.EndpointI> array, int begin, int mid, int end, IComparer<IceInternal.EndpointI> comparator)
+ {
+ int i = begin;
+ int j = mid;
+ int k = 0;
+
+ IceInternal.EndpointI[] tmp = new IceInternal.EndpointI[end - begin];
+ while(i < mid && j < end)
+ {
+ if(comparator.Compare(array[i], array[j]) <= 0)
+ {
+ tmp[k++] = array[i++];
+ }
+ else
+ {
+ tmp[k++] = array[j++];
+ }
+ }
+
+ while(i < mid)
+ {
+ tmp[k++] = array[i++];
+ }
+ while(j < end)
+ {
+ tmp[k++] = array[j++];
+ }
+ for(i = 0; i < (end - begin); ++i)
+ {
+ array[begin + i] = tmp[i];
+ }
+ }
private static EndpointComparator _preferNonSecureEndpointComparator = new EndpointComparator(false);
private static EndpointComparator _preferSecureEndpointComparator = new EndpointComparator(true);