Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -0,0 +1,400 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.Xml
{
using System;
abstract class ArrayHelper<TArgument, TArray>
{
public TArray[] ReadArray(XmlDictionaryReader reader, TArgument localName, TArgument namespaceUri, int maxArrayLength)
{
TArray[][] arrays = null;
TArray[] array = null;
int arrayCount = 0;
int totalRead = 0;
int count;
if (reader.TryGetArrayLength(out count))
{
if (count > maxArrayLength)
XmlExceptionHelper.ThrowMaxArrayLengthOrMaxItemsQuotaExceeded(reader, maxArrayLength);
if (count > XmlDictionaryReader.MaxInitialArrayLength)
count = XmlDictionaryReader.MaxInitialArrayLength;
}
else
{
count = 32;
}
while (true)
{
array = new TArray[count];
int read = 0;
while (read < array.Length)
{
int actual = ReadArray(reader, localName, namespaceUri, array, read, array.Length - read);
if (actual == 0)
break;
read += actual;
}
if (totalRead > maxArrayLength - read)
XmlExceptionHelper.ThrowMaxArrayLengthOrMaxItemsQuotaExceeded(reader, maxArrayLength);
totalRead += read;
if (read < array.Length || reader.NodeType == XmlNodeType.EndElement)
break;
if (arrays == null)
arrays = new TArray[32][];
arrays[arrayCount++] = array;
count = count * 2;
}
if (totalRead != array.Length || arrayCount > 0)
{
TArray[] newArray = new TArray[totalRead];
int offset = 0;
for (int i = 0; i < arrayCount; i++)
{
Array.Copy(arrays[i], 0, newArray, offset, arrays[i].Length);
offset += arrays[i].Length;
}
Array.Copy(array, 0, newArray, offset, totalRead - offset);
array = newArray;
}
return array;
}
public void WriteArray(XmlDictionaryWriter writer, string prefix, TArgument localName, TArgument namespaceUri, XmlDictionaryReader reader)
{
int count;
if (reader.TryGetArrayLength(out count))
count = Math.Min(count, 256);
else
count = 256;
TArray[] array = new TArray[count];
while (true)
{
int actual = ReadArray(reader, localName, namespaceUri, array, 0, array.Length);
if (actual == 0)
break;
WriteArray(writer, prefix, localName, namespaceUri, array, 0, actual);
}
}
protected abstract int ReadArray(XmlDictionaryReader reader, TArgument localName, TArgument namespaceUri, TArray[] array, int offset, int count);
protected abstract void WriteArray(XmlDictionaryWriter writer, string prefix, TArgument localName, TArgument namespaceUri, TArray[] array, int offset, int count);
}
// Supported array types
// bool
// Int16
// Int32
// Int64
// Float
// Double
// Decimal
// DateTime
// Guid
// TimeSpan
// Int8 is not supported since sbyte[] is non-cls compliant, and uncommon
// UniqueId is not supported since elements may be variable size strings
class BooleanArrayHelperWithString : ArrayHelper<string, bool>
{
static public readonly BooleanArrayHelperWithString Instance = new BooleanArrayHelperWithString();
protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, bool[] array, int offset, int count)
{
return reader.ReadArray(localName, namespaceUri, array, offset, count);
}
protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, bool[] array, int offset, int count)
{
writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
}
}
class BooleanArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, bool>
{
static public readonly BooleanArrayHelperWithDictionaryString Instance = new BooleanArrayHelperWithDictionaryString();
protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, bool[] array, int offset, int count)
{
return reader.ReadArray(localName, namespaceUri, array, offset, count);
}
protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, bool[] array, int offset, int count)
{
writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
}
}
class Int16ArrayHelperWithString : ArrayHelper<string, Int16>
{
static public readonly Int16ArrayHelperWithString Instance = new Int16ArrayHelperWithString();
protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, Int16[] array, int offset, int count)
{
return reader.ReadArray(localName, namespaceUri, array, offset, count);
}
protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, Int16[] array, int offset, int count)
{
writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
}
}
class Int16ArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, Int16>
{
static public readonly Int16ArrayHelperWithDictionaryString Instance = new Int16ArrayHelperWithDictionaryString();
protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, Int16[] array, int offset, int count)
{
return reader.ReadArray(localName, namespaceUri, array, offset, count);
}
protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, Int16[] array, int offset, int count)
{
writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
}
}
class Int32ArrayHelperWithString : ArrayHelper<string, Int32>
{
static public readonly Int32ArrayHelperWithString Instance = new Int32ArrayHelperWithString();
protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, Int32[] array, int offset, int count)
{
return reader.ReadArray(localName, namespaceUri, array, offset, count);
}
protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, Int32[] array, int offset, int count)
{
writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
}
}
class Int32ArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, Int32>
{
static public readonly Int32ArrayHelperWithDictionaryString Instance = new Int32ArrayHelperWithDictionaryString();
protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, Int32[] array, int offset, int count)
{
return reader.ReadArray(localName, namespaceUri, array, offset, count);
}
protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, Int32[] array, int offset, int count)
{
writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
}
}
class Int64ArrayHelperWithString : ArrayHelper<string, Int64>
{
static public readonly Int64ArrayHelperWithString Instance = new Int64ArrayHelperWithString();
protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, Int64[] array, int offset, int count)
{
return reader.ReadArray(localName, namespaceUri, array, offset, count);
}
protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, Int64[] array, int offset, int count)
{
writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
}
}
class Int64ArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, Int64>
{
static public readonly Int64ArrayHelperWithDictionaryString Instance = new Int64ArrayHelperWithDictionaryString();
protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, Int64[] array, int offset, int count)
{
return reader.ReadArray(localName, namespaceUri, array, offset, count);
}
protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, Int64[] array, int offset, int count)
{
writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
}
}
class SingleArrayHelperWithString : ArrayHelper<string, float>
{
static public readonly SingleArrayHelperWithString Instance = new SingleArrayHelperWithString();
protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, float[] array, int offset, int count)
{
return reader.ReadArray(localName, namespaceUri, array, offset, count);
}
protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, float[] array, int offset, int count)
{
writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
}
}
class SingleArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, float>
{
static public readonly SingleArrayHelperWithDictionaryString Instance = new SingleArrayHelperWithDictionaryString();
protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, float[] array, int offset, int count)
{
return reader.ReadArray(localName, namespaceUri, array, offset, count);
}
protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, float[] array, int offset, int count)
{
writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
}
}
class DoubleArrayHelperWithString : ArrayHelper<string, double>
{
static public readonly DoubleArrayHelperWithString Instance = new DoubleArrayHelperWithString();
protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, double[] array, int offset, int count)
{
return reader.ReadArray(localName, namespaceUri, array, offset, count);
}
protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, double[] array, int offset, int count)
{
writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
}
}
class DoubleArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, double>
{
static public readonly DoubleArrayHelperWithDictionaryString Instance = new DoubleArrayHelperWithDictionaryString();
protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, double[] array, int offset, int count)
{
return reader.ReadArray(localName, namespaceUri, array, offset, count);
}
protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, double[] array, int offset, int count)
{
writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
}
}
class DecimalArrayHelperWithString : ArrayHelper<string, decimal>
{
static public readonly DecimalArrayHelperWithString Instance = new DecimalArrayHelperWithString();
protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, decimal[] array, int offset, int count)
{
return reader.ReadArray(localName, namespaceUri, array, offset, count);
}
protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, decimal[] array, int offset, int count)
{
writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
}
}
class DecimalArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, decimal>
{
static public readonly DecimalArrayHelperWithDictionaryString Instance = new DecimalArrayHelperWithDictionaryString();
protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, decimal[] array, int offset, int count)
{
return reader.ReadArray(localName, namespaceUri, array, offset, count);
}
protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, decimal[] array, int offset, int count)
{
writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
}
}
class DateTimeArrayHelperWithString : ArrayHelper<string, DateTime>
{
static public readonly DateTimeArrayHelperWithString Instance = new DateTimeArrayHelperWithString();
protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, DateTime[] array, int offset, int count)
{
return reader.ReadArray(localName, namespaceUri, array, offset, count);
}
protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, DateTime[] array, int offset, int count)
{
writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
}
}
class DateTimeArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, DateTime>
{
static public readonly DateTimeArrayHelperWithDictionaryString Instance = new DateTimeArrayHelperWithDictionaryString();
protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, DateTime[] array, int offset, int count)
{
return reader.ReadArray(localName, namespaceUri, array, offset, count);
}
protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, DateTime[] array, int offset, int count)
{
writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
}
}
class GuidArrayHelperWithString : ArrayHelper<string, Guid>
{
static public readonly GuidArrayHelperWithString Instance = new GuidArrayHelperWithString();
protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, Guid[] array, int offset, int count)
{
return reader.ReadArray(localName, namespaceUri, array, offset, count);
}
protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, Guid[] array, int offset, int count)
{
writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
}
}
class GuidArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, Guid>
{
static public readonly GuidArrayHelperWithDictionaryString Instance = new GuidArrayHelperWithDictionaryString();
protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, Guid[] array, int offset, int count)
{
return reader.ReadArray(localName, namespaceUri, array, offset, count);
}
protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, Guid[] array, int offset, int count)
{
writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
}
}
class TimeSpanArrayHelperWithString : ArrayHelper<string, TimeSpan>
{
static public readonly TimeSpanArrayHelperWithString Instance = new TimeSpanArrayHelperWithString();
protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, TimeSpan[] array, int offset, int count)
{
return reader.ReadArray(localName, namespaceUri, array, offset, count);
}
protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, TimeSpan[] array, int offset, int count)
{
writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
}
}
class TimeSpanArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, TimeSpan>
{
static public readonly TimeSpanArrayHelperWithDictionaryString Instance = new TimeSpanArrayHelperWithDictionaryString();
protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, TimeSpan[] array, int offset, int count)
{
return reader.ReadArray(localName, namespaceUri, array, offset, count);
}
protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, TimeSpan[] array, int offset, int count)
{
writer.WriteArray(prefix, localName, namespaceUri, array, offset, count);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.Xml
{
using System.IO;
public interface IFragmentCapableXmlDictionaryWriter
{
bool CanFragment { get; }
void StartFragment(Stream stream, bool generateSelfContainedTextFragment);
void EndFragment();
void WriteFragment(byte[] buffer, int offset, int count);
}
}

View File

@@ -0,0 +1,13 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.Xml
{
using System.IO;
public interface IStreamProvider
{
Stream GetStream();
void ReleaseStream(Stream stream);
}
}

View File

@@ -0,0 +1,12 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Xml
{
public interface IXmlDictionary
{
bool TryLookup(string value, out XmlDictionaryString result);
bool TryLookup(int key, out XmlDictionaryString result);
bool TryLookup(XmlDictionaryString value, out XmlDictionaryString result);
}
}

View File

@@ -0,0 +1,253 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.Xml
{
using System.Runtime;
enum PrefixHandleType
{
Empty,
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
Buffer,
Max,
}
class PrefixHandle
{
XmlBufferReader bufferReader;
PrefixHandleType type;
int offset;
int length;
static string[] prefixStrings = { "", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
static byte[] prefixBuffer = { (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f', (byte)'g', (byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m', (byte)'n', (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', (byte)'v', (byte)'w', (byte)'x', (byte)'y', (byte)'z' };
public PrefixHandle(XmlBufferReader bufferReader)
{
this.bufferReader = bufferReader;
}
public void SetValue(PrefixHandleType type)
{
Fx.Assert(type != PrefixHandleType.Buffer, "");
this.type = type;
}
public void SetValue(PrefixHandle prefix)
{
this.type = prefix.type;
this.offset = prefix.offset;
this.length = prefix.length;
}
public void SetValue(int offset, int length)
{
if (length == 0)
{
SetValue(PrefixHandleType.Empty);
return;
}
if (length == 1)
{
byte ch = bufferReader.GetByte(offset);
if (ch >= 'a' && ch <= 'z')
{
SetValue(GetAlphaPrefix(ch - 'a'));
return;
}
}
this.type = PrefixHandleType.Buffer;
this.offset = offset;
this.length = length;
}
public bool IsEmpty
{
get
{
return type == PrefixHandleType.Empty;
}
}
public bool IsXmlns
{
get
{
if (type != PrefixHandleType.Buffer)
return false;
if (this.length != 5)
return false;
byte[] buffer = bufferReader.Buffer;
int offset = this.offset;
return buffer[offset + 0] == 'x' &&
buffer[offset + 1] == 'm' &&
buffer[offset + 2] == 'l' &&
buffer[offset + 3] == 'n' &&
buffer[offset + 4] == 's';
}
}
public bool IsXml
{
get
{
if (type != PrefixHandleType.Buffer)
return false;
if (this.length != 3)
return false;
byte[] buffer = bufferReader.Buffer;
int offset = this.offset;
return buffer[offset + 0] == 'x' &&
buffer[offset + 1] == 'm' &&
buffer[offset + 2] == 'l';
}
}
public bool TryGetShortPrefix(out PrefixHandleType type)
{
type = this.type;
return (type != PrefixHandleType.Buffer);
}
public static string GetString(PrefixHandleType type)
{
Fx.Assert(type != PrefixHandleType.Buffer, "");
return prefixStrings[(int)type];
}
public static PrefixHandleType GetAlphaPrefix(int index)
{
Fx.Assert(index >= 0 && index < 26, "");
return (PrefixHandleType)(PrefixHandleType.A + index);
}
public static byte[] GetString(PrefixHandleType type, out int offset, out int length)
{
Fx.Assert(type != PrefixHandleType.Buffer, "");
if (type == PrefixHandleType.Empty)
{
offset = 0;
length = 0;
}
else
{
length = 1;
offset = (int)(type - PrefixHandleType.A);
}
return prefixBuffer;
}
public string GetString(XmlNameTable nameTable)
{
PrefixHandleType type = this.type;
if (type != PrefixHandleType.Buffer)
return GetString(type);
else
return bufferReader.GetString(offset, length, nameTable);
}
public string GetString()
{
PrefixHandleType type = this.type;
if (type != PrefixHandleType.Buffer)
return GetString(type);
else
return bufferReader.GetString(offset, length);
}
public byte[] GetString(out int offset, out int length)
{
PrefixHandleType type = this.type;
if (type != PrefixHandleType.Buffer)
return GetString(type, out offset, out length);
else
{
offset = this.offset;
length = this.length;
return bufferReader.Buffer;
}
}
public int CompareTo(PrefixHandle that)
{
return GetString().CompareTo(that.GetString());
}
bool Equals2(PrefixHandle prefix2)
{
PrefixHandleType type1 = this.type;
PrefixHandleType type2 = prefix2.type;
if (type1 != type2)
return false;
if (type1 != PrefixHandleType.Buffer)
return true;
if (this.bufferReader == prefix2.bufferReader)
return bufferReader.Equals2(this.offset, this.length, prefix2.offset, prefix2.length);
else
return bufferReader.Equals2(this.offset, this.length, prefix2.bufferReader, prefix2.offset, prefix2.length);
}
bool Equals2(string prefix2)
{
PrefixHandleType type = this.type;
if (type != PrefixHandleType.Buffer)
return GetString(type) == prefix2;
return bufferReader.Equals2(this.offset, this.length, prefix2);
}
bool Equals2(XmlDictionaryString prefix2)
{
return Equals2(prefix2.Value);
}
static public bool operator ==(PrefixHandle prefix1, string prefix2)
{
return prefix1.Equals2(prefix2);
}
static public bool operator !=(PrefixHandle prefix1, string prefix2)
{
return !prefix1.Equals2(prefix2);
}
static public bool operator ==(PrefixHandle prefix1, XmlDictionaryString prefix2)
{
return prefix1.Equals2(prefix2);
}
static public bool operator !=(PrefixHandle prefix1, XmlDictionaryString prefix2)
{
return !prefix1.Equals2(prefix2);
}
static public bool operator ==(PrefixHandle prefix1, PrefixHandle prefix2)
{
return prefix1.Equals2(prefix2);
}
static public bool operator !=(PrefixHandle prefix1, PrefixHandle prefix2)
{
return !prefix1.Equals2(prefix2);
}
public override bool Equals(object obj)
{
PrefixHandle that = obj as PrefixHandle;
if (object.ReferenceEquals(that, null))
return false;
return this == that;
}
public override string ToString()
{
return GetString();
}
public override int GetHashCode()
{
return GetString().GetHashCode();
}
}
}

View File

@@ -0,0 +1,300 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.Xml
{
using System.Runtime;
enum StringHandleConstStringType
{
Type = 0,
Root = 1,
Item = 2
}
class StringHandle
{
XmlBufferReader bufferReader;
StringHandleType type;
int key;
int offset;
int length;
static string[] constStrings = {
"type",
"root",
"item"
};
public StringHandle(XmlBufferReader bufferReader)
{
this.bufferReader = bufferReader;
SetValue(0, 0);
}
public void SetValue(int offset, int length)
{
this.type = StringHandleType.UTF8;
this.offset = offset;
this.length = length;
}
public void SetConstantValue(StringHandleConstStringType constStringType)
{
type = StringHandleType.ConstString;
key = (int)constStringType;
}
public void SetValue(int offset, int length, bool escaped)
{
this.type = (escaped ? StringHandleType.EscapedUTF8 : StringHandleType.UTF8);
this.offset = offset;
this.length = length;
}
public void SetValue(int key)
{
this.type = StringHandleType.Dictionary;
this.key = key;
}
public void SetValue(StringHandle value)
{
this.type = value.type;
this.key = value.key;
this.offset = value.offset;
this.length = value.length;
}
public bool IsEmpty
{
get
{
if (type == StringHandleType.UTF8)
return length == 0;
return Equals2(string.Empty);
}
}
public bool IsXmlns
{
get
{
if (type == StringHandleType.UTF8)
{
if (this.length != 5)
return false;
byte[] buffer = bufferReader.Buffer;
int offset = this.offset;
return buffer[offset + 0] == 'x' &&
buffer[offset + 1] == 'm' &&
buffer[offset + 2] == 'l' &&
buffer[offset + 3] == 'n' &&
buffer[offset + 4] == 's';
}
return Equals2("xmlns");
}
}
public void ToPrefixHandle(PrefixHandle prefix)
{
Fx.Assert(type == StringHandleType.UTF8, "");
prefix.SetValue(offset, length);
}
public string GetString(XmlNameTable nameTable)
{
StringHandleType type = this.type;
if (type == StringHandleType.UTF8)
return bufferReader.GetString(offset, length, nameTable);
if (type == StringHandleType.Dictionary)
return nameTable.Add(bufferReader.GetDictionaryString(key).Value);
if (type == StringHandleType.ConstString)
return nameTable.Add(constStrings[key]);
Fx.Assert(type == StringHandleType.EscapedUTF8, "");
return bufferReader.GetEscapedString(offset, length, nameTable);
}
public string GetString()
{
StringHandleType type = this.type;
if (type == StringHandleType.UTF8)
return bufferReader.GetString(offset, length);
if (type == StringHandleType.Dictionary)
return bufferReader.GetDictionaryString(key).Value;
if (type == StringHandleType.ConstString)
return constStrings[key];
Fx.Assert(type == StringHandleType.EscapedUTF8, "");
return bufferReader.GetEscapedString(offset, length);
}
public byte[] GetString(out int offset, out int length)
{
StringHandleType type = this.type;
if (type == StringHandleType.UTF8)
{
offset = this.offset;
length = this.length;
return bufferReader.Buffer;
}
if (type == StringHandleType.Dictionary)
{
byte[] buffer = bufferReader.GetDictionaryString(this.key).ToUTF8();
offset = 0;
length = buffer.Length;
return buffer;
}
if (type == StringHandleType.ConstString)
{
byte[] buffer = XmlConverter.ToBytes(constStrings[key]);
offset = 0;
length = buffer.Length;
return buffer;
}
else
{
Fx.Assert(type == StringHandleType.EscapedUTF8, "");
byte[] buffer = XmlConverter.ToBytes(bufferReader.GetEscapedString(this.offset, this.length));
offset = 0;
length = buffer.Length;
return buffer;
}
}
public bool TryGetDictionaryString(out XmlDictionaryString value)
{
if (type == StringHandleType.Dictionary)
{
value = bufferReader.GetDictionaryString(key);
return true;
}
else if (IsEmpty)
{
value = XmlDictionaryString.Empty;
return true;
}
value = null;
return false;
}
public override string ToString()
{
return GetString();
}
bool Equals2(int key2, XmlBufferReader bufferReader2)
{
StringHandleType type = this.type;
if (type == StringHandleType.Dictionary)
return bufferReader.Equals2(this.key, key2, bufferReader2);
if (type == StringHandleType.UTF8)
return bufferReader.Equals2(this.offset, this.length, bufferReader2.GetDictionaryString(key2).Value);
Fx.Assert(type == StringHandleType.EscapedUTF8 || type == StringHandleType.ConstString, "");
return GetString() == bufferReader.GetDictionaryString(key2).Value;
}
bool Equals2(XmlDictionaryString xmlString2)
{
StringHandleType type = this.type;
if (type == StringHandleType.Dictionary)
return bufferReader.Equals2(this.key, xmlString2);
if (type == StringHandleType.UTF8)
return bufferReader.Equals2(this.offset, this.length, xmlString2.ToUTF8());
Fx.Assert(type == StringHandleType.EscapedUTF8 || type == StringHandleType.ConstString, "");
return GetString() == xmlString2.Value;
}
bool Equals2(string s2)
{
StringHandleType type = this.type;
if (type == StringHandleType.Dictionary)
return bufferReader.GetDictionaryString(this.key).Value == s2;
if (type == StringHandleType.UTF8)
return bufferReader.Equals2(this.offset, this.length, s2);
Fx.Assert(type == StringHandleType.EscapedUTF8 || type == StringHandleType.ConstString, "");
return GetString() == s2;
}
bool Equals2(int offset2, int length2, XmlBufferReader bufferReader2)
{
StringHandleType type = this.type;
if (type == StringHandleType.Dictionary)
return bufferReader2.Equals2(offset2, length2, bufferReader.GetDictionaryString(this.key).Value);
if (type == StringHandleType.UTF8)
return bufferReader.Equals2(this.offset, this.length, bufferReader2, offset2, length2);
Fx.Assert(type == StringHandleType.EscapedUTF8 || type == StringHandleType.ConstString, "");
return GetString() == bufferReader.GetString(offset2, length2);
}
bool Equals2(StringHandle s2)
{
StringHandleType type = s2.type;
if (type == StringHandleType.Dictionary)
return Equals2(s2.key, s2.bufferReader);
if (type == StringHandleType.UTF8)
return Equals2(s2.offset, s2.length, s2.bufferReader);
Fx.Assert(type == StringHandleType.EscapedUTF8 || type == StringHandleType.ConstString, "");
return Equals2(s2.GetString());
}
static public bool operator ==(StringHandle s1, XmlDictionaryString xmlString2)
{
return s1.Equals2(xmlString2);
}
static public bool operator !=(StringHandle s1, XmlDictionaryString xmlString2)
{
return !s1.Equals2(xmlString2);
}
static public bool operator ==(StringHandle s1, string s2)
{
return s1.Equals2(s2);
}
static public bool operator !=(StringHandle s1, string s2)
{
return !s1.Equals2(s2);
}
static public bool operator ==(StringHandle s1, StringHandle s2)
{
return s1.Equals2(s2);
}
static public bool operator !=(StringHandle s1, StringHandle s2)
{
return !s1.Equals2(s2);
}
public int CompareTo(StringHandle that)
{
if (this.type == StringHandleType.UTF8 && that.type == StringHandleType.UTF8)
return bufferReader.Compare(this.offset, this.length, that.offset, that.length);
else
return string.Compare(this.GetString(), that.GetString(), StringComparison.Ordinal);
}
public override bool Equals(object obj)
{
StringHandle that = obj as StringHandle;
if (object.ReferenceEquals(that, null))
return false;
return this == that;
}
public override int GetHashCode()
{
return GetString().GetHashCode();
}
enum StringHandleType
{
Dictionary,
UTF8,
EscapedUTF8,
ConstString
}
}
}

View File

@@ -0,0 +1,431 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.Xml
{
using System.Runtime;
using System.Runtime.Serialization; // for SR
using System.Security;
public class UniqueId
{
Int64 idLow;
Int64 idHigh;
[Fx.Tag.SecurityNote(Critical = "Some SecurityCritical unsafe code assumes that this field has been validated.")]
[SecurityCritical]
string s;
const int guidLength = 16;
const int uuidLength = 45;
static short[] char2val = new short[256]
{
/* 0-15 */ 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100,
/* 16-31 */ 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100,
/* 32-47 */ 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100,
/* 48-63 */ 0x000, 0x010, 0x020, 0x030, 0x040, 0x050, 0x060, 0x070, 0x080, 0x090, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100,
/* 64-79 */ 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100,
/* 80-95 */ 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100,
/* 96-111 */ 0x100, 0x0A0, 0x0B0, 0x0C0, 0x0D0, 0x0E0, 0x0F0, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100,
/* 112-127 */ 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100,
/* 0-15 */ 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100,
/* 16-31 */ 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100,
/* 32-47 */ 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100,
/* 48-63 */ 0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x007, 0x008, 0x009, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100,
/* 64-79 */ 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100,
/* 80-95 */ 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100,
/* 96-111 */ 0x100, 0x00A, 0x00B, 0x00C, 0x00D, 0x00E, 0x00F, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100,
/* 112-127 */ 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100,
};
const string val2char = "0123456789abcdef";
public UniqueId() : this(Guid.NewGuid())
{
}
public UniqueId(Guid guid) : this(guid.ToByteArray())
{
}
public UniqueId(byte[] guid) : this(guid, 0)
{
}
[Fx.Tag.SecurityNote(Critical = "Contains unsafe code.",
Safe = "Unsafe code is effectively encapsulated, all inputs are validated.")]
[SecuritySafeCritical]
unsafe public UniqueId(byte[] guid, int offset)
{
if (guid == null)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("guid"));
if (offset < 0)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("offset", SR.GetString(SR.ValueMustBeNonNegative)));
if (offset > guid.Length)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("offset", SR.GetString(SR.OffsetExceedsBufferSize, guid.Length)));
if (guidLength > guid.Length - offset)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.XmlArrayTooSmallInput, guidLength), "guid"));
fixed (byte* pb = &guid[offset])
{
this.idLow = UnsafeGetInt64(pb);
this.idHigh = UnsafeGetInt64(&pb[8]);
}
}
[Fx.Tag.SecurityNote(Critical = "Contains unsafe code.",
Safe = "Unsafe code is effectively encapsulated, all inputs are validated.")]
[SecuritySafeCritical]
unsafe public UniqueId(string value)
{
if (value == null)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
if (value.Length == 0)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SR.GetString(SR.XmlInvalidUniqueId)));
fixed (char* pch = value)
{
UnsafeParse(pch, value.Length);
}
this.s = value;
}
[Fx.Tag.SecurityNote(Critical = "Contains unsafe code.",
Safe = "Unsafe code is effectively encapsulated, all inputs are validated.")]
[SecuritySafeCritical]
unsafe public UniqueId(char[] chars, int offset, int count)
{
if (chars == null)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("chars"));
if (offset < 0)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("offset", SR.GetString(SR.ValueMustBeNonNegative)));
if (offset > chars.Length)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("offset", SR.GetString(SR.OffsetExceedsBufferSize, chars.Length)));
if (count < 0)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("count", SR.GetString(SR.ValueMustBeNonNegative)));
if (count > chars.Length - offset)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("count", SR.GetString(SR.SizeExceedsRemainingBufferSpace, chars.Length - offset)));
if (count == 0)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SR.GetString(SR.XmlInvalidUniqueId)));
fixed (char* pch = &chars[offset])
{
UnsafeParse(pch, count);
}
if (!IsGuid)
{
this.s = new string(chars, offset, count);
}
}
public int CharArrayLength
{
[Fx.Tag.SecurityNote(Critical = "Accesses critical field 's'.",
Safe = "Doesn't leak any control or data.")]
[SecuritySafeCritical]
get
{
if (s != null)
return s.Length;
return uuidLength;
}
}
[Fx.Tag.SecurityNote(Critical = "Contains unsafe code. Caller needs to validate arguments.")]
[SecurityCritical]
unsafe int UnsafeDecode(short* char2val, char ch1, char ch2)
{
if ((ch1 | ch2) >= 0x80)
return 0x100;
return char2val[ch1] | char2val[0x80 + ch2];
}
[Fx.Tag.SecurityNote(Critical = "Contains unsafe code. Caller needs to validate arguments.")]
[SecurityCritical]
unsafe void UnsafeEncode(char* val2char, byte b, char* pch)
{
pch[0] = val2char[b >> 4];
pch[1] = val2char[b & 0x0F];
}
public bool IsGuid
{
get
{
return ((idLow | idHigh) != 0);
}
}
// It must be the case that comparing UniqueId's as strings yields the same result as comparing UniqueId's as
// their binary equivalent. This means that there must be a 1-1 relationship between a string and its binary
// equivalent. Therefore, for example, we cannot accept both upper and lower case hex chars since there would
// then be more than 1 string that mapped to a binary equivalent.
[Fx.Tag.SecurityNote(Critical = "Contains unsafe code. Caller needs to validate arguments.")]
[SecurityCritical]
unsafe void UnsafeParse(char* chars, int charCount)
{
// 1 2 3 4
// 012345678901234567890123456789012345678901234
// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
if (charCount != uuidLength ||
chars[0] != 'u' || chars[1] != 'r' || chars[2] != 'n' || chars[3] != ':' ||
chars[4] != 'u' || chars[5] != 'u' || chars[6] != 'i' || chars[7] != 'd' || chars[8] != ':' ||
chars[17] != '-' || chars[22] != '-' || chars[27] != '-' || chars[32] != '-')
{
return;
}
byte* bytes = stackalloc byte[guidLength];
int i = 0;
int j = 0;
fixed (short* ps = char2val)
{
short* _char2val = ps;
// 0 1 2 3 4
// 012345678901234567890123456789012345678901234
// urn:uuid:aabbccdd-eeff-gghh-0011-223344556677
//
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
// ddccbbaaffeehhgg0011223344556677
i = UnsafeDecode(_char2val, chars[15], chars[16]); bytes[0] = (byte)i; j |= i;
i = UnsafeDecode(_char2val, chars[13], chars[14]); bytes[1] = (byte)i; j |= i;
i = UnsafeDecode(_char2val, chars[11], chars[12]); bytes[2] = (byte)i; j |= i;
i = UnsafeDecode(_char2val, chars[9], chars[10]); bytes[3] = (byte)i; j |= i;
i = UnsafeDecode(_char2val, chars[20], chars[21]); bytes[4] = (byte)i; j |= i;
i = UnsafeDecode(_char2val, chars[18], chars[19]); bytes[5] = (byte)i; j |= i;
i = UnsafeDecode(_char2val, chars[25], chars[26]); bytes[6] = (byte)i; j |= i;
i = UnsafeDecode(_char2val, chars[23], chars[24]); bytes[7] = (byte)i; j |= i;
i = UnsafeDecode(_char2val, chars[28], chars[29]); bytes[8] = (byte)i; j |= i;
i = UnsafeDecode(_char2val, chars[30], chars[31]); bytes[9] = (byte)i; j |= i;
i = UnsafeDecode(_char2val, chars[33], chars[34]); bytes[10] = (byte)i; j |= i;
i = UnsafeDecode(_char2val, chars[35], chars[36]); bytes[11] = (byte)i; j |= i;
i = UnsafeDecode(_char2val, chars[37], chars[38]); bytes[12] = (byte)i; j |= i;
i = UnsafeDecode(_char2val, chars[39], chars[40]); bytes[13] = (byte)i; j |= i;
i = UnsafeDecode(_char2val, chars[41], chars[42]); bytes[14] = (byte)i; j |= i;
i = UnsafeDecode(_char2val, chars[43], chars[44]); bytes[15] = (byte)i; j |= i;
if (j >= 0x100)
return;
this.idLow = UnsafeGetInt64(bytes);
this.idHigh = UnsafeGetInt64(&bytes[8]);
}
}
[Fx.Tag.SecurityNote(Critical = "Contains unsafe code.",
Safe = "Unsafe code is effectively encapsulated, all inputs are validated.")]
[SecuritySafeCritical]
unsafe public int ToCharArray(char[] chars, int offset)
{
int count = CharArrayLength;
if (chars == null)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("chars"));
if (offset < 0)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("offset", SR.GetString(SR.ValueMustBeNonNegative)));
if (offset > chars.Length)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("offset", SR.GetString(SR.OffsetExceedsBufferSize, chars.Length)));
if (count > chars.Length - offset)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("chars", SR.GetString(SR.XmlArrayTooSmallOutput, count)));
if (s != null)
{
s.CopyTo(0, chars, offset, count);
}
else
{
byte* bytes = stackalloc byte[guidLength];
UnsafeSetInt64(this.idLow, bytes);
UnsafeSetInt64(this.idHigh, &bytes[8]);
fixed (char* _pch = &chars[offset])
{
char* pch = _pch;
pch[0] = 'u';
pch[1] = 'r';
pch[2] = 'n';
pch[3] = ':';
pch[4] = 'u';
pch[5] = 'u';
pch[6] = 'i';
pch[7] = 'd';
pch[8] = ':';
pch[17] = '-';
pch[22] = '-';
pch[27] = '-';
pch[32] = '-';
fixed (char* ps = val2char)
{
char* _val2char = ps;
UnsafeEncode(_val2char, bytes[0], &pch[15]);
UnsafeEncode(_val2char, bytes[1], &pch[13]);
UnsafeEncode(_val2char, bytes[2], &pch[11]);
UnsafeEncode(_val2char, bytes[3], &pch[9]);
UnsafeEncode(_val2char, bytes[4], &pch[20]);
UnsafeEncode(_val2char, bytes[5], &pch[18]);
UnsafeEncode(_val2char, bytes[6], &pch[25]);
UnsafeEncode(_val2char, bytes[7], &pch[23]);
UnsafeEncode(_val2char, bytes[8], &pch[28]);
UnsafeEncode(_val2char, bytes[9], &pch[30]);
UnsafeEncode(_val2char, bytes[10], &pch[33]);
UnsafeEncode(_val2char, bytes[11], &pch[35]);
UnsafeEncode(_val2char, bytes[12], &pch[37]);
UnsafeEncode(_val2char, bytes[13], &pch[39]);
UnsafeEncode(_val2char, bytes[14], &pch[41]);
UnsafeEncode(_val2char, bytes[15], &pch[43]);
}
}
}
return count;
}
public bool TryGetGuid(out Guid guid)
{
byte[] buffer = new byte[guidLength];
if (!TryGetGuid(buffer, 0))
{
guid = Guid.Empty;
return false;
}
guid = new Guid(buffer);
return true;
}
[Fx.Tag.SecurityNote(Critical = "Contains unsafe code.",
Safe = "Unsafe code is effectively encapsulated, all inputs are validated.")]
[SecuritySafeCritical]
unsafe public bool TryGetGuid(byte[] buffer, int offset)
{
if (!IsGuid)
return false;
if (buffer == null)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("buffer"));
if (offset < 0)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("offset", SR.GetString(SR.ValueMustBeNonNegative)));
if (offset > buffer.Length)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("offset", SR.GetString(SR.OffsetExceedsBufferSize, buffer.Length)));
if (guidLength > buffer.Length - offset)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("buffer", SR.GetString(SR.XmlArrayTooSmallOutput, guidLength)));
fixed (byte* pb = &buffer[offset])
{
UnsafeSetInt64(this.idLow, pb);
UnsafeSetInt64(this.idHigh, &pb[8]);
}
return true;
}
[Fx.Tag.SecurityNote(Critical = "Accesses critical field 's'.",
Safe = "Doesn't allow unchecked write access to the field.")]
[SecuritySafeCritical]
unsafe public override string ToString()
{
if (s == null)
{
int length = CharArrayLength;
char[] chars = new char[length];
ToCharArray(chars, 0);
s = new string(chars, 0, length);
}
return s;
}
static public bool operator ==(UniqueId id1, UniqueId id2)
{
if (object.ReferenceEquals(id1, null) && object.ReferenceEquals(id2, null))
return true;
if (object.ReferenceEquals(id1, null) || object.ReferenceEquals(id2, null))
return false;
#pragma warning suppress 56506 // [....], checks for whether id1 and id2 are null done above.
if (id1.IsGuid && id2.IsGuid)
{
return id1.idLow == id2.idLow && id1.idHigh == id2.idHigh;
}
return id1.ToString() == id2.ToString();
}
static public bool operator !=(UniqueId id1, UniqueId id2)
{
return !(id1 == id2);
}
public override bool Equals(object obj)
{
return this == (obj as UniqueId);
}
public override int GetHashCode()
{
if (IsGuid)
{
Int64 hash = (idLow ^ idHigh);
return ((int)(hash >> 32)) ^ ((int)hash);
}
else
{
return ToString().GetHashCode();
}
}
[Fx.Tag.SecurityNote(Critical = "Contains unsafe code. Caller needs to validate arguments.")]
[SecurityCritical]
unsafe Int64 UnsafeGetInt64(byte* pb)
{
Int32 idLow = UnsafeGetInt32(pb);
Int32 idHigh = UnsafeGetInt32(&pb[4]);
return (((Int64)idHigh) << 32) | ((UInt32)idLow);
}
[Fx.Tag.SecurityNote(Critical = "Contains unsafe code. Caller needs to validate arguments.")]
[SecurityCritical]
unsafe Int32 UnsafeGetInt32(byte* pb)
{
int value = pb[3];
value <<= 8;
value |= pb[2];
value <<= 8;
value |= pb[1];
value <<= 8;
value |= pb[0];
return value;
}
[Fx.Tag.SecurityNote(Critical = "Contains unsafe code. Caller needs to validate arguments.")]
[SecurityCritical]
unsafe void UnsafeSetInt64(Int64 value, byte* pb)
{
UnsafeSetInt32((int)value, pb);
UnsafeSetInt32((int)(value >> 32), &pb[4]);
}
[Fx.Tag.SecurityNote(Critical = "Contains unsafe code. Caller needs to validate arguments.")]
[SecurityCritical]
unsafe void UnsafeSetInt32(Int32 value, byte* pb)
{
pb[0] = (byte)value;
value >>= 8;
pb[1] = (byte)value;
value >>= 8;
pb[2] = (byte)value;
value >>= 8;
pb[3] = (byte)value;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
6b1de6eb1d939934205dc38fa1676f6dfdb83186

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,275 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.Xml
{
// Element => StartElement Attribute* Content EndElement
// | StartElement Attribute* Text // Text must be WithEndElement
// | Array StartElement Attribute* EndElement type MB32(Count) byte[Count * sizeof(type)]
// StartElement => ShortElementNode Name(LocalName)
// | ElementNode Name(Prefix) Name(LocalName)
// | ShortDictionaryElementNode MB32(LocalName)
// | PrefixDictionaryElement[A-Z]Node MB32(LocalName)
// | DictionaryElementNode Name(Prefix) MB32(LocalName)
// | PrefixElement[A-Z]Node Name(LocalName)
// EndElement => EndElementNode
// Content => (Element | ArrayElement | Text | Comment)*
// Attribute => ShortAttributeNode Name(LocalName) Text
// | AttributeNode Name(Prefix) Name(LocalName) Text
// | ShortDictionaryAttributeNode MB32(LocalName) Text
// | DictionaryAttributeNode Name(Prefix) MB32(LocalName) Text
// | ShortXmlnsAttributeNode Name(Namespace)
// | XmlnsAttributeNode Name(Prefix) Name(Namespace)
// | ShortDictionaryXmlnsAttributeNode MB32(Namespace)
// | DictionaryXmlnsAttributeNode Name(Prefix) MB32(Namespace)
// | PrefixAttribute[A-Z] Name(LocalName) Text
// | PrefixDictionaryAttribute[A-Z] MB32(LocalName) Text
// Text => BinaryTextNode
// | CharsTextNode
// | EmptyTextNode
// | DictionaryTextNode MB32(Id)
// | ZeroTextNode
// | OneTextNode
// | TrueTextNode
// | FalseTextNode
// | Int8TextNode Int8
// | Int16TextNode Int16
// | Int32TextNode Int32
// | Int64TextNode Int64
// | FloatTextNode Float
// | DoubleTextNode Double
// | DecimalTextNode Decimal
// | DateTimeTextNode DateTime
// | StartListNode Text* EndListNode // Restriction: Cannot nest ListNode
// | UniqueIdTextNode byte[16] // byte[16] is a Guid (from Guid.ToBinary()) (urn:uuid:xxxx-xxxx-xxx)
// | GuidTextNode byte[16] // byte[16] is a Guid (from Guid.ToBinary()) (xxxx-xxxx-xxx)
// | TimeSpanNode Int64
// | UInt64TextNode UInt64
// | BoolTextNode Int8
// BinaryText => Bytes8TextNode UInt8 byte*
// | Bytes16TextNode UInt16 byte*
// | Bytes32TextNode UInt31 byte*
// CharsText => Chars8TextNode UInt8 byte* // UTF8Chars
// | Chars16TextNode UInt16 byte*
// | Chars32TextNode Unt31 byte*
// | UnicodeChars8TextNode UInt8 char*
// | UnicodeChars16TextNode UInt16 char*
// | UnicodeChars32TextNode UInt31 char*
// | QNameDictionaryTextNode UInt8 MB32(LocalName) // UInt8 0-25 => 'a'-'z'
// Comment => CommentNode Name(Text)
// Name => MB32 byte* // Length, UTF8Chars
// MB32(x:x>=0x80) => byte(0x80 | (x & 0x7F)) MB32(x >> 7)
// MB32(x:x<0x80) => byte(x)
// In order to help differentiate text from binary (where someone mixes up format and implementation) we overlay binary
// nodes that are illegal to start a document with text characters that are legal to start a document. Specifically these values are:
// ' ' = 32
// '\t' = 9
// '\n' = 10
// '\r' = 13
// '<' = 60
// The attribute nodes (MinAttribute to MaxAttribute) overlay all of these values and are invalid as the first byte of the document
enum XmlBinaryNodeType
{
// ProcessingInstruction = 0, // Reserved (Not supported)
EndElement = 1,
Comment = 2,
Array = 3,
MinAttribute = Array + 1,
ShortAttribute = MinAttribute + 0,
Attribute = MinAttribute + 1,
ShortDictionaryAttribute = MinAttribute + 2,
DictionaryAttribute = MinAttribute + 3,
ShortXmlnsAttribute = MinAttribute + 4,
XmlnsAttribute = MinAttribute + 5,
ShortDictionaryXmlnsAttribute = MinAttribute + 6,
DictionaryXmlnsAttribute = MinAttribute + 7,
PrefixDictionaryAttributeA = MinAttribute + 8,
PrefixDictionaryAttributeB = PrefixDictionaryAttributeA + 1,
PrefixDictionaryAttributeC = PrefixDictionaryAttributeB + 1,
PrefixDictionaryAttributeD = PrefixDictionaryAttributeC + 1,
PrefixDictionaryAttributeE = PrefixDictionaryAttributeD + 1,
PrefixDictionaryAttributeF = PrefixDictionaryAttributeE + 1,
PrefixDictionaryAttributeG = PrefixDictionaryAttributeF + 1,
PrefixDictionaryAttributeH = PrefixDictionaryAttributeG + 1,
PrefixDictionaryAttributeI = PrefixDictionaryAttributeH + 1,
PrefixDictionaryAttributeJ = PrefixDictionaryAttributeI + 1,
PrefixDictionaryAttributeK = PrefixDictionaryAttributeJ + 1,
PrefixDictionaryAttributeL = PrefixDictionaryAttributeK + 1,
PrefixDictionaryAttributeM = PrefixDictionaryAttributeL + 1,
PrefixDictionaryAttributeN = PrefixDictionaryAttributeM + 1,
PrefixDictionaryAttributeO = PrefixDictionaryAttributeN + 1,
PrefixDictionaryAttributeP = PrefixDictionaryAttributeO + 1,
PrefixDictionaryAttributeQ = PrefixDictionaryAttributeP + 1,
PrefixDictionaryAttributeR = PrefixDictionaryAttributeQ + 1,
PrefixDictionaryAttributeS = PrefixDictionaryAttributeR + 1,
PrefixDictionaryAttributeT = PrefixDictionaryAttributeS + 1,
PrefixDictionaryAttributeU = PrefixDictionaryAttributeT + 1,
PrefixDictionaryAttributeV = PrefixDictionaryAttributeU + 1,
PrefixDictionaryAttributeW = PrefixDictionaryAttributeV + 1,
PrefixDictionaryAttributeX = PrefixDictionaryAttributeW + 1,
PrefixDictionaryAttributeY = PrefixDictionaryAttributeX + 1,
PrefixDictionaryAttributeZ = PrefixDictionaryAttributeY + 1,
PrefixAttributeA = PrefixDictionaryAttributeZ + 1,
PrefixAttributeB = PrefixAttributeA + 1,
PrefixAttributeC = PrefixAttributeB + 1,
PrefixAttributeD = PrefixAttributeC + 1,
PrefixAttributeE = PrefixAttributeD + 1,
PrefixAttributeF = PrefixAttributeE + 1,
PrefixAttributeG = PrefixAttributeF + 1,
PrefixAttributeH = PrefixAttributeG + 1,
PrefixAttributeI = PrefixAttributeH + 1,
PrefixAttributeJ = PrefixAttributeI + 1,
PrefixAttributeK = PrefixAttributeJ + 1,
PrefixAttributeL = PrefixAttributeK + 1,
PrefixAttributeM = PrefixAttributeL + 1,
PrefixAttributeN = PrefixAttributeM + 1,
PrefixAttributeO = PrefixAttributeN + 1,
PrefixAttributeP = PrefixAttributeO + 1,
PrefixAttributeQ = PrefixAttributeP + 1,
PrefixAttributeR = PrefixAttributeQ + 1,
PrefixAttributeS = PrefixAttributeR + 1,
PrefixAttributeT = PrefixAttributeS + 1,
PrefixAttributeU = PrefixAttributeT + 1,
PrefixAttributeV = PrefixAttributeU + 1,
PrefixAttributeW = PrefixAttributeV + 1,
PrefixAttributeX = PrefixAttributeW + 1,
PrefixAttributeY = PrefixAttributeX + 1,
PrefixAttributeZ = PrefixAttributeY + 1,
MaxAttribute = PrefixAttributeZ,
MinElement = MaxAttribute + 1,
ShortElement = MinElement,
Element = MinElement + 1,
ShortDictionaryElement = MinElement + 2,
DictionaryElement = MinElement + 3,
PrefixDictionaryElementA = MinElement + 4,
PrefixDictionaryElementB = PrefixDictionaryElementA + 1,
PrefixDictionaryElementC = PrefixDictionaryElementB + 1,
PrefixDictionaryElementD = PrefixDictionaryElementC + 1,
PrefixDictionaryElementE = PrefixDictionaryElementD + 1,
PrefixDictionaryElementF = PrefixDictionaryElementE + 1,
PrefixDictionaryElementG = PrefixDictionaryElementF + 1,
PrefixDictionaryElementH = PrefixDictionaryElementG + 1,
PrefixDictionaryElementI = PrefixDictionaryElementH + 1,
PrefixDictionaryElementJ = PrefixDictionaryElementI + 1,
PrefixDictionaryElementK = PrefixDictionaryElementJ + 1,
PrefixDictionaryElementL = PrefixDictionaryElementK + 1,
PrefixDictionaryElementM = PrefixDictionaryElementL + 1,
PrefixDictionaryElementN = PrefixDictionaryElementM + 1,
PrefixDictionaryElementO = PrefixDictionaryElementN + 1,
PrefixDictionaryElementP = PrefixDictionaryElementO + 1,
PrefixDictionaryElementQ = PrefixDictionaryElementP + 1,
PrefixDictionaryElementR = PrefixDictionaryElementQ + 1,
PrefixDictionaryElementS = PrefixDictionaryElementR + 1,
PrefixDictionaryElementT = PrefixDictionaryElementS + 1,
PrefixDictionaryElementU = PrefixDictionaryElementT + 1,
PrefixDictionaryElementV = PrefixDictionaryElementU + 1,
PrefixDictionaryElementW = PrefixDictionaryElementV + 1,
PrefixDictionaryElementX = PrefixDictionaryElementW + 1,
PrefixDictionaryElementY = PrefixDictionaryElementX + 1,
PrefixDictionaryElementZ = PrefixDictionaryElementY + 1,
PrefixElementA = PrefixDictionaryElementZ + 1,
PrefixElementB = PrefixElementA + 1,
PrefixElementC = PrefixElementB + 1,
PrefixElementD = PrefixElementC + 1,
PrefixElementE = PrefixElementD + 1,
PrefixElementF = PrefixElementE + 1,
PrefixElementG = PrefixElementF + 1,
PrefixElementH = PrefixElementG + 1,
PrefixElementI = PrefixElementH + 1,
PrefixElementJ = PrefixElementI + 1,
PrefixElementK = PrefixElementJ + 1,
PrefixElementL = PrefixElementK + 1,
PrefixElementM = PrefixElementL + 1,
PrefixElementN = PrefixElementM + 1,
PrefixElementO = PrefixElementN + 1,
PrefixElementP = PrefixElementO + 1,
PrefixElementQ = PrefixElementP + 1,
PrefixElementR = PrefixElementQ + 1,
PrefixElementS = PrefixElementR + 1,
PrefixElementT = PrefixElementS + 1,
PrefixElementU = PrefixElementT + 1,
PrefixElementV = PrefixElementU + 1,
PrefixElementW = PrefixElementV + 1,
PrefixElementX = PrefixElementW + 1,
PrefixElementY = PrefixElementX + 1,
PrefixElementZ = PrefixElementY + 1,
MaxElement = PrefixElementZ,
// MinorVersion = MaxElement + 1, // Reserved (Not supported)
MinText = 0x80, // Must be even
ZeroText = MinText,
OneText = MinText + 1 * 2,
FalseText = MinText + 2 * 2,
TrueText = MinText + 3 * 2,
Int8Text = MinText + 4 * 2,
Int16Text = MinText + 5 * 2,
Int32Text = MinText + 6 * 2,
Int64Text = MinText + 7 * 2,
FloatText = MinText + 8 * 2,
DoubleText = MinText + 9 * 2,
DecimalText = MinText + 10 * 2,
DateTimeText = MinText + 11 * 2,
Chars8Text = MinText + 12 * 2,
Chars16Text = MinText + 13 * 2,
Chars32Text = MinText + 14 * 2,
Bytes8Text = MinText + 15 * 2,
Bytes16Text = MinText + 16 * 2,
Bytes32Text = MinText + 17 * 2,
StartListText = MinText + 18 * 2,
EndListText = MinText + 19 * 2,
EmptyText = MinText + 20 * 2,
DictionaryText = MinText + 21 * 2,
UniqueIdText = MinText + 22 * 2,
TimeSpanText = MinText + 23 * 2,
GuidText = MinText + 24 * 2,
UInt64Text = MinText + 25 * 2,
BoolText = MinText + 26 * 2,
UnicodeChars8Text = MinText + 27 * 2,
UnicodeChars16Text = MinText + 28 * 2,
UnicodeChars32Text = MinText + 29 * 2,
QNameDictionaryText = MinText + 30 * 2,
ZeroTextWithEndElement = ZeroText + 1,
OneTextWithEndElement = OneText + 1,
FalseTextWithEndElement = FalseText + 1,
TrueTextWithEndElement = TrueText + 1,
Int8TextWithEndElement = Int8Text + 1,
Int16TextWithEndElement = Int16Text + 1,
Int32TextWithEndElement = Int32Text + 1,
Int64TextWithEndElement = Int64Text + 1,
FloatTextWithEndElement = FloatText + 1,
DoubleTextWithEndElement = DoubleText + 1,
DecimalTextWithEndElement = DecimalText + 1,
DateTimeTextWithEndElement = DateTimeText + 1,
Chars8TextWithEndElement = Chars8Text + 1,
Chars16TextWithEndElement = Chars16Text + 1,
Chars32TextWithEndElement = Chars32Text + 1,
Bytes8TextWithEndElement = Bytes8Text + 1,
Bytes16TextWithEndElement = Bytes16Text + 1,
Bytes32TextWithEndElement = Bytes32Text + 1,
StartListTextWithEndElement = StartListText + 1,
EndListTextWithEndElement = EndListText + 1,
EmptyTextWithEndElement = EmptyText + 1,
DictionaryTextWithEndElement = DictionaryText + 1,
UniqueIdTextWithEndElement = UniqueIdText + 1,
TimeSpanTextWithEndElement = TimeSpanText + 1,
GuidTextWithEndElement = GuidText + 1,
UInt64TextWithEndElement = UInt64Text + 1,
BoolTextWithEndElement = BoolText + 1,
UnicodeChars8TextWithEndElement = UnicodeChars8Text + 1,
UnicodeChars16TextWithEndElement = UnicodeChars16Text + 1,
UnicodeChars32TextWithEndElement = UnicodeChars32Text + 1,
QNameDictionaryTextWithEndElement = QNameDictionaryText + 1,
MaxText = QNameDictionaryTextWithEndElement
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,130 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
using StringHandle = System.Int64;
namespace System.Xml
{
using System.Xml;
using System.Collections.Generic;
using System.Runtime.Serialization;
public class XmlBinaryReaderSession : IXmlDictionary
{
const int MaxArrayEntries = 2048;
XmlDictionaryString[] strings;
Dictionary<int, XmlDictionaryString> stringDict;
public XmlBinaryReaderSession()
{
}
public XmlDictionaryString Add(int id, string value)
{
if (id < 0)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(SR.GetString(SR.XmlInvalidID)));
if (value == null)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
XmlDictionaryString xmlString;
if (TryLookup(id, out xmlString))
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.XmlIDDefined)));
xmlString = new XmlDictionaryString(this, value, id);
if (id >= MaxArrayEntries)
{
if (stringDict == null)
this.stringDict = new Dictionary<int, XmlDictionaryString>();
this.stringDict.Add(id, xmlString);
}
else
{
if (strings == null)
{
strings = new XmlDictionaryString[Math.Max(id + 1, 16)];
}
else if (id >= strings.Length)
{
XmlDictionaryString[] newStrings = new XmlDictionaryString[Math.Min(Math.Max(id + 1, strings.Length * 2), MaxArrayEntries)];
Array.Copy(strings, newStrings, strings.Length);
strings = newStrings;
}
strings[id] = xmlString;
}
return xmlString;
}
public bool TryLookup(int key, out XmlDictionaryString result)
{
if (strings != null && key >= 0 && key < strings.Length)
{
result = strings[key];
return result != null;
}
else if (key >= MaxArrayEntries)
{
if (this.stringDict != null)
return this.stringDict.TryGetValue(key, out result);
}
result = null;
return false;
}
public bool TryLookup(string value, out XmlDictionaryString result)
{
if (value == null)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
if (strings != null)
{
for (int i = 0; i < strings.Length; i++)
{
XmlDictionaryString s = strings[i];
if (s != null && s.Value == value)
{
result = s;
return true;
}
}
}
if (this.stringDict != null)
{
foreach (XmlDictionaryString s in this.stringDict.Values)
{
if (s.Value == value)
{
result = s;
return true;
}
}
}
result = null;
return false;
}
public bool TryLookup(XmlDictionaryString value, out XmlDictionaryString result)
{
if (value == null)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("value"));
if (value.Dictionary != this)
{
result = null;
return false;
}
result = value;
return true;
}
public void Clear()
{
if (strings != null)
Array.Clear(strings, 0, strings.Length);
if (this.stringDict != null)
this.stringDict.Clear();
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,260 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.Xml
{
using System;
using System.Xml;
using System.Collections;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections.Generic;
using System.Collections.ObjectModel;
public class XmlBinaryWriterSession
{
PriorityDictionary<string, int> strings;
PriorityDictionary<IXmlDictionary, IntArray> maps;
int nextKey;
public XmlBinaryWriterSession()
{
this.nextKey = 0;
this.maps = new PriorityDictionary<IXmlDictionary, IntArray>();
this.strings = new PriorityDictionary<string, int>();
}
public virtual bool TryAdd(XmlDictionaryString value, out int key)
{
IntArray keys;
if (value == null)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
if (maps.TryGetValue(value.Dictionary, out keys))
{
key = (keys[value.Key] - 1);
if (key != -1)
{
// If the key is already set, then something is wrong
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.XmlKeyAlreadyExists)));
}
key = Add(value.Value);
keys[value.Key] = (key + 1);
return true;
}
key = Add(value.Value);
keys = AddKeys(value.Dictionary, value.Key + 1);
keys[value.Key] = (key + 1);
return true;
}
int Add(string s)
{
int key = this.nextKey++;
strings.Add(s, key);
return key;
}
IntArray AddKeys(IXmlDictionary dictionary, int minCount)
{
IntArray keys = new IntArray(Math.Max(minCount, 16));
maps.Add(dictionary, keys);
return keys;
}
public void Reset()
{
nextKey = 0;
maps.Clear();
strings.Clear();
}
internal bool TryLookup(XmlDictionaryString s, out int key)
{
IntArray keys;
if (maps.TryGetValue(s.Dictionary, out keys))
{
key = (keys[s.Key] - 1);
if (key != -1)
{
return true;
}
}
if (strings.TryGetValue(s.Value, out key))
{
if (keys == null)
{
keys = AddKeys(s.Dictionary, s.Key + 1);
}
keys[s.Key] = (key + 1);
return true;
}
key = -1;
return false;
}
class PriorityDictionary<K, V> where K : class
{
Dictionary<K, V> dictionary;
Entry[] list;
int listCount;
int now;
public PriorityDictionary()
{
list = new Entry[16];
}
public void Clear()
{
now = 0;
listCount = 0;
Array.Clear(list, 0, list.Length);
if (dictionary != null)
dictionary.Clear();
}
public bool TryGetValue(K key, out V value)
{
for (int i = 0; i < listCount; i++)
{
if (list[i].Key == key)
{
value = list[i].Value;
list[i].Time = Now;
return true;
}
}
for (int i = 0; i < listCount; i++)
{
if (list[i].Key.Equals(key))
{
value = list[i].Value;
list[i].Time = Now;
return true;
}
}
if (dictionary == null)
{
value = default(V);
return false;
}
if (!dictionary.TryGetValue(key, out value))
{
return false;
}
int minIndex = 0;
int minTime = list[0].Time;
for (int i = 1; i < listCount; i++)
{
if (list[i].Time < minTime)
{
minIndex = i;
minTime = list[i].Time;
}
}
list[minIndex].Key = key;
list[minIndex].Value = value;
list[minIndex].Time = Now;
return true;
}
public void Add(K key, V value)
{
if (listCount < list.Length)
{
list[listCount].Key = key;
list[listCount].Value = value;
listCount++;
}
else
{
if (dictionary == null)
{
dictionary = new Dictionary<K, V>();
for (int i = 0; i < listCount; i++)
{
dictionary.Add(list[i].Key, list[i].Value);
}
}
dictionary.Add(key, value);
}
}
int Now
{
get
{
if (++now == int.MaxValue)
{
DecreaseAll();
}
return now;
}
}
void DecreaseAll()
{
for (int i = 0; i < listCount; i++)
{
list[i].Time /= 2;
}
now /= 2;
}
struct Entry
{
public K Key;
public V Value;
public int Time;
}
}
class IntArray
{
int[] array;
public IntArray(int size)
{
this.array = new int[size];
}
public int this[int index]
{
get
{
if (index >= array.Length)
return 0;
return array[index];
}
set
{
if (index >= array.Length)
{
int[] newArray = new int[Math.Max(index + 1, array.Length * 2)];
Array.Copy(array, newArray, array.Length);
array = newArray;
}
array[index] = value;
}
}
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,451 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.Xml
{
using System;
using System.IO;
using System.Xml;
using System.Text;
using System.Diagnostics;
#if NO
public class XmlDelegatedReader : XmlDictionaryReader, IXmlLineInfo
{
XmlDictionaryReader reader;
public XmlDelegatedReader(XmlDictionaryReader reader)
{
if (reader == null)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader"));
this.reader = reader;
}
protected XmlDictionaryReader Reader
{
get
{
return reader;
}
}
public override int AttributeCount
{
get
{
return reader.AttributeCount;
}
}
public override string BaseURI
{
get
{
return reader.BaseURI;
}
}
public override void Close()
{
reader.Close();
}
public override int Depth
{
get
{
return reader.Depth;
}
}
public override bool EOF
{
get
{
return reader.EOF;
}
}
public override string GetAttribute(int index)
{
return reader.GetAttribute(index);
}
public override string GetAttribute(string name)
{
return reader.GetAttribute(name);
}
public override string GetAttribute(string name, string ns)
{
return reader.GetAttribute(name, ns);
}
public override bool HasValue
{
get
{
return reader.HasValue;
}
}
public override bool IsDefault
{
get
{
return reader.IsDefault;
}
}
public override bool IsEmptyElement
{
get
{
return reader.IsEmptyElement;
}
}
public override bool IsLocalName(string localName)
{
return reader.IsLocalName(localName);
}
public override bool IsNamespaceUri(string ns)
{
return reader.IsNamespaceUri(ns);
}
public override bool IsStartElement(string localName)
{
return reader.IsStartElement(localName);
}
public override bool IsStartElement(string localName, string ns)
{
return reader.IsStartElement(localName, ns);
}
public override string LocalName
{
get
{
return reader.LocalName;
}
}
public override string LookupNamespace(string ns)
{
return reader.LookupNamespace(ns);
}
public override void MoveToAttribute(int index)
{
reader.MoveToAttribute(index);
}
public override bool MoveToAttribute(string name)
{
return reader.MoveToAttribute(name);
}
public override bool MoveToAttribute(string name, string ns)
{
return reader.MoveToAttribute(name, ns);
}
public override bool MoveToElement()
{
return reader.MoveToElement();
}
public override bool MoveToFirstAttribute()
{
return reader.MoveToFirstAttribute();
}
public override bool MoveToNextAttribute()
{
return reader.MoveToNextAttribute();
}
public override string Name
{
get
{
return reader.Name;
}
}
public override string NamespaceURI
{
get
{
return reader.NamespaceURI;
}
}
public override XmlNameTable NameTable
{
get
{
return reader.NameTable;
}
}
public override XmlNodeType NodeType
{
get
{
return reader.NodeType;
}
}
public override string Prefix
{
get
{
return reader.Prefix;
}
}
public override char QuoteChar
{
get
{
return reader.QuoteChar;
}
}
public override bool Read()
{
return reader.Read();
}
public override bool ReadAttributeValue()
{
return reader.ReadAttributeValue();
}
public override string ReadElementString(string localName)
{
return reader.ReadElementString(localName);
}
public override string ReadElementString(string localName, string ns)
{
return reader.ReadElementString(localName, ns);
}
public override string ReadInnerXml()
{
return reader.ReadInnerXml();
}
public override string ReadOuterXml()
{
return reader.ReadOuterXml();
}
public override void ReadStartElement(string localName)
{
reader.ReadStartElement(localName);
}
public override void ReadStartElement(string localName, string ns)
{
reader.ReadStartElement(localName, ns);
}
public override void ReadEndElement()
{
reader.ReadEndElement();
}
public override string ReadString()
{
return reader.ReadString();
}
public override ReadState ReadState
{
get
{
return reader.ReadState;
}
}
public override void ResolveEntity()
{
reader.ResolveEntity();
}
public override string this[int index]
{
get
{
return reader[index];
}
}
public override string this[string name]
{
get
{
return reader[name];
}
}
public override string this[string name, string ns]
{
get
{
return reader[name, ns];
}
}
public override string Value
{
get
{
return reader.Value;
}
}
public override string XmlLang
{
get
{
return reader.XmlLang;
}
}
public override XmlSpace XmlSpace
{
get
{
return reader.XmlSpace;
}
}
public override int ReadBase64(byte[] buffer, int offset, int count)
{
return reader.ReadBase64(buffer, offset, count);
}
public override int ReadBinHex(byte[] buffer, int offset, int count)
{
return reader.ReadBinHex(buffer, offset, count);
}
public override int ReadChars(char[] chars, int offset, int count)
{
return reader.ReadChars(chars, offset, count);
}
public override int ReadValueAsChars(char[] chars, int offset, int count)
{
return reader.ReadValueAsChars(chars, offset, count);
}
public override Type ValueType
{
get
{
return reader.ValueType;
}
}
public override Boolean ReadValueAsBoolean()
{
return reader.ReadValueAsBoolean();
}
public override DateTime ReadValueAsDateTime()
{
return reader.ReadValueAsDateTime();
}
public override Decimal ReadValueAsDecimal()
{
return reader.ReadValueAsDecimal();
}
public override Double ReadValueAsDouble()
{
return reader.ReadValueAsDouble();
}
public override Int32 ReadValueAsInt32()
{
return reader.ReadValueAsInt32();
}
public override Int64 ReadValueAsInt64()
{
return reader.ReadValueAsInt64();
}
public override Single ReadValueAsSingle()
{
return reader.ReadValueAsSingle();
}
public override string ReadValueAsString()
{
return reader.ReadValueAsString();
}
public override object ReadValueAs(Type type)
{
return reader.ReadValueAs(type);
}
public override bool IsStartSubsetElement()
{
return reader.IsStartSubsetElement();
}
public override ArraySegment<byte> GetSubset(bool advance)
{
return reader.GetSubset(advance);
}
public bool HasLineInfo()
{
IXmlLineInfo lineInfo = reader as IXmlLineInfo;
if (lineInfo == null)
return false;
return lineInfo.HasLineInfo();
}
public int LineNumber
{
get
{
IXmlLineInfo lineInfo = reader as IXmlLineInfo;
if (lineInfo == null)
return 1;
return lineInfo.LineNumber;
}
}
public int LinePosition
{
get
{
IXmlLineInfo lineInfo = reader as IXmlLineInfo;
if (lineInfo == null)
return 1;
return lineInfo.LinePosition;
}
}
}
#endif
}

Some files were not shown because too many files have changed in this diff Show More