summaryrefslogtreecommitdiff
path: root/cs/src/Ice/BasicStream.cs
diff options
context:
space:
mode:
Diffstat (limited to 'cs/src/Ice/BasicStream.cs')
-rw-r--r--cs/src/Ice/BasicStream.cs136
1 files changed, 66 insertions, 70 deletions
diff --git a/cs/src/Ice/BasicStream.cs b/cs/src/Ice/BasicStream.cs
index 78c7ba2aecb..802ae64c8f2 100644
--- a/cs/src/Ice/BasicStream.cs
+++ b/cs/src/Ice/BasicStream.cs
@@ -15,14 +15,14 @@ namespace IceInternal
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
-#if !COMPACT
+#if !COMPACT && !SILVERLIGHT
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
#endif
using System.Threading;
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
internal static class NativeMethods
{
[DllImport("bzip2.dll")]
@@ -52,7 +52,7 @@ namespace IceInternal
static BasicStream()
{
-#if MANAGED || COMPACT
+#if MANAGED || COMPACT || SILVERLIGHT
//
// Protocol compression is not supported when using managed code.
//
@@ -234,7 +234,7 @@ namespace IceInternal
other._minSeqSize = _minSeqSize;
_minSeqSize = tmpMinSeqSize;
- ArrayList tmpObjectList = other._objectList;
+ List<Ice.Object> tmpObjectList = other._objectList;
other._objectList = _objectList;
_objectList = tmpObjectList;
@@ -597,15 +597,15 @@ namespace IceInternal
throw new Ice.MarshalException("type ids require an encapsulation");
}
- object o = _writeEncapsStack.typeIdMap[id];
- if(o != null)
+ int index;
+ if(_writeEncapsStack.typeIdMap.TryGetValue(id, out index))
{
writeBool(true);
- writeSize((int)o);
+ writeSize(index);
}
else
{
- int index = ++_writeEncapsStack.typeIdIndex;
+ index = ++_writeEncapsStack.typeIdIndex;
_writeEncapsStack.typeIdMap[id] = index;
writeBool(false);
writeString(id);
@@ -625,8 +625,7 @@ namespace IceInternal
if(isIndex)
{
index = readSize();
- id = (string)_readEncapsStack.typeIdMap[index];
- if(id == null)
+ if(!_readEncapsStack.typeIdMap.TryGetValue(index, out id))
{
throw new Ice.UnmarshalOutOfBoundsException("Missing type ID");
}
@@ -769,7 +768,7 @@ namespace IceInternal
public void writeSerializable(object o)
{
-#if !COMPACT
+#if !COMPACT && !SILVERLIGHT
if(o == null)
{
writeSize(0);
@@ -874,7 +873,7 @@ namespace IceInternal
public object readSerializable()
{
-#if !COMPACT
+#if !COMPACT && !SILVERLIGHT
int sz = readAndCheckSeqSize(1);
if(sz == 0)
{
@@ -2049,35 +2048,33 @@ namespace IceInternal
if(_writeEncapsStack.toBeMarshaledMap == null) // Lazy initialization
{
- _writeEncapsStack.toBeMarshaledMap = new Hashtable();
- _writeEncapsStack.marshaledMap = new Hashtable();
- _writeEncapsStack.typeIdMap = new Hashtable();
+ _writeEncapsStack.toBeMarshaledMap = new Dictionary<Ice.Object, int>();
+ _writeEncapsStack.marshaledMap = new Dictionary<Ice.Object, int>();
+ _writeEncapsStack.typeIdMap = new Dictionary<string, int>();
}
if(v != null)
{
//
- // Look for this instance in the to-be-marshaled map.
- //
- object p = _writeEncapsStack.toBeMarshaledMap[v];
- if(p == null)
- {
- //
- // Didn't find it, try the marshaled map next.
- //
- object q = _writeEncapsStack.marshaledMap[v];
- if(q == null)
+ // Look for this instance in the to-be-marshaled map.
+ //
+ int p;
+ if(!_writeEncapsStack.toBeMarshaledMap.TryGetValue(v, out p))
+ {
+ //
+ // Didn't find it, try the marshaled map next.
+ //
+ if(!_writeEncapsStack.marshaledMap.TryGetValue(v, out p))
{
- //
- // We haven't seen this instance previously,
- // create a new index, and insert it into the
- // to-be-marshaled map.
- //
- q = ++_writeEncapsStack.writeIndex;
- _writeEncapsStack.toBeMarshaledMap[v] = q;
- }
- p = q;
- }
- writeInt(-((int)p));
+ //
+ // We haven't seen this instance previously,
+ // create a new index, and insert it into the
+ // to-be-marshaled map.
+ //
+ p = ++_writeEncapsStack.writeIndex;
+ _writeEncapsStack.toBeMarshaledMap[v] = p;
+ }
+ }
+ writeInt(-p);
}
else
{
@@ -2104,9 +2101,9 @@ namespace IceInternal
if(_readEncapsStack.patchMap == null) // Lazy initialization
{
- _readEncapsStack.patchMap = new Hashtable();
- _readEncapsStack.unmarshaledMap = new Hashtable();
- _readEncapsStack.typeIdMap = new Hashtable();
+ _readEncapsStack.patchMap = new Dictionary<int, List<IceInternal.IPatcher> >();
+ _readEncapsStack.unmarshaledMap = new Dictionary<int, Ice.Object>();
+ _readEncapsStack.typeIdMap = new Dictionary<int, string>();
}
int index = readInt();
@@ -2122,15 +2119,15 @@ namespace IceInternal
if(index < 0)
{
int i = -index;
- IceUtilInternal.LinkedList patchlist = (IceUtilInternal.LinkedList)_readEncapsStack.patchMap[i];
- if(patchlist == null)
+ List<IceInternal.IPatcher> patchlist;
+ if(!_readEncapsStack.patchMap.TryGetValue(i, out patchlist))
{
//
// We have no outstanding instances to be patched
// for this index, so make a new entry in the
// patch map.
//
- patchlist = new IceUtilInternal.LinkedList();
+ patchlist = new List<IceInternal.IPatcher>();
_readEncapsStack.patchMap[i] = patchlist;
}
//
@@ -2241,7 +2238,7 @@ namespace IceInternal
//
if(_objectList == null)
{
- _objectList = new ArrayList();
+ _objectList = new List<Ice.Object>();
}
_objectList.Add(v);
@@ -2346,9 +2343,10 @@ namespace IceInternal
{
while(_writeEncapsStack.toBeMarshaledMap.Count > 0)
{
- Hashtable savedMap = new Hashtable(_writeEncapsStack.toBeMarshaledMap);
+ Dictionary<Ice.Object, int> savedMap =
+ new Dictionary<Ice.Object, int>(_writeEncapsStack.toBeMarshaledMap);
writeSize(savedMap.Count);
- foreach(DictionaryEntry e in savedMap)
+ foreach(KeyValuePair<Ice.Object, int> e in savedMap)
{
//
// Add an instance from the old
@@ -2367,7 +2365,7 @@ namespace IceInternal
// pass, substract what we have marshaled from the
// toBeMarshaledMap.
//
- foreach(DictionaryEntry e in savedMap)
+ foreach(KeyValuePair<Ice.Object, int> e in savedMap)
{
_writeEncapsStack.toBeMarshaledMap.Remove(e.Key);
}
@@ -2452,10 +2450,10 @@ namespace IceInternal
// must be null.) Patch any pointers in the patch map with
// the new address.
//
- Debug.Assert( ((object)instanceIndex != null && (object)patchIndex == null)
- || ((object)instanceIndex == null && (object)patchIndex != null));
-
- IceUtilInternal.LinkedList patchlist;
+ Debug.Assert(((object)instanceIndex != null && (object)patchIndex == null) ||
+ ((object)instanceIndex == null && (object)patchIndex != null));
+
+ List<IceInternal.IPatcher> patchlist;
Ice.Object v;
if((object)instanceIndex != null)
{
@@ -2463,12 +2461,11 @@ namespace IceInternal
// We have just unmarshaled an instance -- check if
// something needs patching for that instance.
//
- patchlist = (IceUtilInternal.LinkedList)_readEncapsStack.patchMap[instanceIndex];
- if(patchlist == null)
+ if(!_readEncapsStack.patchMap.TryGetValue((int)instanceIndex, out patchlist))
{
return; // We don't have anything to patch for the instance just unmarshaled.
}
- v = (Ice.Object)_readEncapsStack.unmarshaledMap[instanceIndex];
+ v = _readEncapsStack.unmarshaledMap[(int)instanceIndex];
patchIndex = instanceIndex;
}
else
@@ -2477,12 +2474,11 @@ namespace IceInternal
// We have just unmarshaled an index -- check if we
// have unmarshaled the instance for that index yet.
//
- v = (Ice.Object)_readEncapsStack.unmarshaledMap[patchIndex];
- if(v == null)
+ if(!_readEncapsStack.unmarshaledMap.TryGetValue((int)patchIndex, out v))
{
return; // We haven't unmarshaled the instance for this index yet.
}
- patchlist = (IceUtilInternal.LinkedList)_readEncapsStack.patchMap[patchIndex];
+ patchlist = _readEncapsStack.patchMap[(int)patchIndex];
}
Debug.Assert(patchlist != null && patchlist.Count > 0);
Debug.Assert(v != null);
@@ -2516,10 +2512,10 @@ namespace IceInternal
// nothing left to patch for that index for the time
// being.
//
- _readEncapsStack.patchMap.Remove(patchIndex);
+ _readEncapsStack.patchMap.Remove((int)patchIndex);
}
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
static string getBZ2Error(int error)
{
string rc;
@@ -2588,7 +2584,7 @@ namespace IceInternal
public bool compress(ref BasicStream cstream, int headerSize, int compressionLevel)
{
-#if MANAGED || COMPACT
+#if MANAGED || COMPACT || SILVERLIGHT
cstream = this;
return false;
#else
@@ -2656,7 +2652,7 @@ namespace IceInternal
public BasicStream uncompress(int headerSize)
{
-#if MANAGED || COMPACT
+#if MANAGED || COMPACT || SILVERLIGHT
return this;
#else
if(!_bzlibInstalled)
@@ -2837,8 +2833,7 @@ namespace IceInternal
lock(_exceptionFactories)
{
- factory = (UserExceptionFactory)_exceptionFactories[id];
- if(factory == null)
+ if(!_exceptionFactories.TryGetValue(id, out factory))
{
try
{
@@ -2885,10 +2880,10 @@ namespace IceInternal
// internal byte encodingMajor; // Currently unused
// internal byte encodingMinor; // Currently unused
- internal Hashtable patchMap;
- internal Hashtable unmarshaledMap;
+ internal Dictionary<int, List<IceInternal.IPatcher> > patchMap;
+ internal Dictionary<int, Ice.Object> unmarshaledMap;
internal int typeIdIndex;
- internal Hashtable typeIdMap;
+ internal Dictionary<int, string> typeIdMap;
internal ReadEncaps next;
internal void reset()
@@ -2908,10 +2903,10 @@ namespace IceInternal
internal int start;
internal int writeIndex;
- internal Hashtable toBeMarshaledMap;
- internal Hashtable marshaledMap;
+ internal Dictionary<Ice.Object, int> toBeMarshaledMap;
+ internal Dictionary<Ice.Object, int> marshaledMap;
internal int typeIdIndex;
- internal Hashtable typeIdMap;
+ internal Dictionary<string, int> typeIdMap;
internal WriteEncaps next;
internal void reset()
@@ -2946,9 +2941,10 @@ namespace IceInternal
int _startSeq;
int _minSeqSize;
- private ArrayList _objectList;
+ private List<Ice.Object> _objectList;
- private static Hashtable _exceptionFactories = new Hashtable(); // <type name, factory> pairs.
+ private static Dictionary<string, UserExceptionFactory> _exceptionFactories =
+ new Dictionary<string, UserExceptionFactory>(); // <type name, factory> pairs.
private static bool _bzlibInstalled;