summaryrefslogtreecommitdiff
path: root/mcs/class/corlib/System
diff options
context:
space:
mode:
Diffstat (limited to 'mcs/class/corlib/System')
-rw-r--r--mcs/class/corlib/System/AggregateException.cs2
-rw-r--r--mcs/class/corlib/System/Array.cs74
-rw-r--r--mcs/class/corlib/System/ArraySegment.cs4
-rw-r--r--mcs/class/corlib/System/Attribute.cs2
-rw-r--r--mcs/class/corlib/System/ConsoleKeyInfo.cs59
-rw-r--r--mcs/class/corlib/System/Convert.cs86
-rw-r--r--mcs/class/corlib/System/Delegate.cs2
-rw-r--r--mcs/class/corlib/System/Enum.cs5
-rw-r--r--mcs/class/corlib/System/Environment.cs2
-rw-r--r--mcs/class/corlib/System/MulticastDelegate.cs9
-rw-r--r--mcs/class/corlib/System/NumberFormatter.cs11
-rw-r--r--mcs/class/corlib/System/Random.cs145
-rw-r--r--mcs/class/corlib/System/String.cs14
-rw-r--r--mcs/class/corlib/System/TimeZone.cs12
-rw-r--r--mcs/class/corlib/System/Tuples.cs274
15 files changed, 419 insertions, 282 deletions
diff --git a/mcs/class/corlib/System/AggregateException.cs b/mcs/class/corlib/System/AggregateException.cs
index 145319acdd..c0df741af1 100644
--- a/mcs/class/corlib/System/AggregateException.cs
+++ b/mcs/class/corlib/System/AggregateException.cs
@@ -163,7 +163,7 @@ namespace System
public override Exception GetBaseException ()
{
- if (innerExceptions == null || innerExceptions.Count == 0)
+ if (innerExceptions == null || innerExceptions.Count != 1)
return this;
return innerExceptions[0].GetBaseException ();
}
diff --git a/mcs/class/corlib/System/Array.cs b/mcs/class/corlib/System/Array.cs
index 91654019f1..756378c56d 100644
--- a/mcs/class/corlib/System/Array.cs
+++ b/mcs/class/corlib/System/Array.cs
@@ -2864,32 +2864,54 @@ namespace System
{
if (array == null)
throw new ArgumentNullException ("array");
+
+ if (match == null)
+ throw new ArgumentNullException ("match");
- return FindLastIndex<T> (array, 0, array.Length, match);
+ return GetLastIndex (array, 0, array.Length, match);
}
public static int FindLastIndex<T> (T [] array, int startIndex, Predicate<T> match)
{
if (array == null)
throw new ArgumentNullException ();
+
+ if (startIndex < 0 || (uint) startIndex > (uint) array.Length)
+ throw new ArgumentOutOfRangeException ("startIndex");
+
+ if (match == null)
+ throw new ArgumentNullException ("match");
- return FindLastIndex<T> (array, startIndex, array.Length - startIndex, match);
+ return GetLastIndex (array, 0, startIndex + 1, match);
}
public static int FindLastIndex<T> (T [] array, int startIndex, int count, Predicate<T> match)
{
if (array == null)
throw new ArgumentNullException ("array");
+
if (match == null)
throw new ArgumentNullException ("match");
+
+ if (startIndex < 0 || (uint) startIndex > (uint) array.Length)
+ throw new ArgumentOutOfRangeException ("startIndex");
- if (startIndex > array.Length || startIndex + count > array.Length)
- throw new ArgumentOutOfRangeException ();
-
- for (int i = startIndex + count - 1; i >= startIndex; i--)
- if (match (array [i]))
+ if (count < 0)
+ throw new ArgumentOutOfRangeException ("count");
+
+ if (startIndex - count + 1 < 0)
+ throw new ArgumentOutOfRangeException ("count must refer to a location within the array");
+
+ return GetLastIndex (array, startIndex - count + 1, count, match);
+ }
+
+ internal static int GetLastIndex<T> (T[] array, int startIndex, int count, Predicate<T> match)
+ {
+ // unlike FindLastIndex, takes regular params for search range
+ for (int i = startIndex + count; i != startIndex;)
+ if (match (array [--i]))
return i;
-
+
return -1;
}
@@ -2897,16 +2919,25 @@ namespace System
{
if (array == null)
throw new ArgumentNullException ("array");
+
+ if (match == null)
+ throw new ArgumentNullException ("match");
- return FindIndex<T> (array, 0, array.Length, match);
+ return GetIndex (array, 0, array.Length, match);
}
public static int FindIndex<T> (T [] array, int startIndex, Predicate<T> match)
{
if (array == null)
throw new ArgumentNullException ("array");
-
- return FindIndex<T> (array, startIndex, array.Length - startIndex, match);
+
+ if (startIndex < 0 || (uint) startIndex > (uint) array.Length)
+ throw new ArgumentOutOfRangeException ("startIndex");
+
+ if (match == null)
+ throw new ArgumentNullException ("match");
+
+ return GetIndex (array, startIndex, array.Length - startIndex, match);
}
public static int FindIndex<T> (T [] array, int startIndex, int count, Predicate<T> match)
@@ -2914,13 +2945,22 @@ namespace System
if (array == null)
throw new ArgumentNullException ("array");
- if (match == null)
- throw new ArgumentNullException ("match");
+ if (startIndex < 0)
+ throw new ArgumentOutOfRangeException ("startIndex");
- if (startIndex > array.Length || startIndex + count > array.Length)
- throw new ArgumentOutOfRangeException ();
-
- for (int i = startIndex; i < startIndex + count; i ++)
+ if (count < 0)
+ throw new ArgumentOutOfRangeException ("count");
+
+ if ((uint) startIndex + (uint) count > (uint) array.Length)
+ throw new ArgumentOutOfRangeException ("index and count exceed length of list");
+
+ return GetIndex (array, startIndex, count, match);
+ }
+
+ internal static int GetIndex<T> (T[] array, int startIndex, int count, Predicate<T> match)
+ {
+ int end = startIndex + count;
+ for (int i = startIndex; i < end; i ++)
if (match (array [i]))
return i;
diff --git a/mcs/class/corlib/System/ArraySegment.cs b/mcs/class/corlib/System/ArraySegment.cs
index 77d76ad069..612e603f60 100644
--- a/mcs/class/corlib/System/ArraySegment.cs
+++ b/mcs/class/corlib/System/ArraySegment.cs
@@ -134,13 +134,13 @@ namespace System
T IList<T>.this[int index] {
get {
- if (index < 0 || count < index)
+ if (index < 0 || index >= count)
throw new ArgumentOutOfRangeException ("index");
return array[offset + index];
}
set {
- if (index < 0 || count < index)
+ if (index < 0 || index >= count)
throw new ArgumentOutOfRangeException ("index");
array[offset + index] = value;
diff --git a/mcs/class/corlib/System/Attribute.cs b/mcs/class/corlib/System/Attribute.cs
index 46d0b775db..be91a7a182 100644
--- a/mcs/class/corlib/System/Attribute.cs
+++ b/mcs/class/corlib/System/Attribute.cs
@@ -258,7 +258,7 @@ namespace System
public override int GetHashCode ()
{
- int result = TypeId.GetHashCode ();
+ int result = GetType ().GetHashCode ();
FieldInfo[] fields = GetType ().GetFields (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
foreach (FieldInfo field in fields) {
diff --git a/mcs/class/corlib/System/ConsoleKeyInfo.cs b/mcs/class/corlib/System/ConsoleKeyInfo.cs
index c62c8d0d03..961cb949d6 100644
--- a/mcs/class/corlib/System/ConsoleKeyInfo.cs
+++ b/mcs/class/corlib/System/ConsoleKeyInfo.cs
@@ -31,80 +31,83 @@ namespace System {
[Serializable]
public struct ConsoleKeyInfo {
internal static ConsoleKeyInfo Empty = new ConsoleKeyInfo ('\0', 0, false, false, false);
- ConsoleKey key;
- char keychar;
- ConsoleModifiers modifiers;
+ ConsoleKey _key;
+ char _keyChar;
+ ConsoleModifiers _mods;
public ConsoleKeyInfo (char keyChar, ConsoleKey key, bool shift, bool alt, bool control)
{
- this.key = key;
- this.keychar = keyChar;
- modifiers = 0;
+ _key = key;
+ _keyChar = keyChar;
+ _mods = 0;
SetModifiers (shift, alt, control);
}
internal ConsoleKeyInfo (ConsoleKeyInfo other)
{
- this.key = other.key;
- this.keychar = other.keychar;
- this.modifiers = other.modifiers;
+ _key = other._key;
+ _keyChar = other._keyChar;
+ _mods = other._mods;
}
internal void SetKey (ConsoleKey key)
{
- this.key = key;
+ _key = key;
}
internal void SetKeyChar (char keyChar)
{
- this.keychar = keyChar;
+ _keyChar = keyChar;
}
internal void SetModifiers (bool shift, bool alt, bool control)
{
- this.modifiers = (shift) ? ConsoleModifiers.Shift : 0;
- this.modifiers |= (alt) ? ConsoleModifiers.Alt : 0;
- this.modifiers |= (control) ? ConsoleModifiers.Control : 0;
+ _mods = (shift) ? ConsoleModifiers.Shift : 0;
+ _mods |= (alt) ? ConsoleModifiers.Alt : 0;
+ _mods |= (control) ? ConsoleModifiers.Control : 0;
}
- public ConsoleKey Key {
- get { return key; }
+ public ConsoleKey Key
+ {
+ get { return _key; }
}
- public char KeyChar {
- get { return keychar; }
+ public char KeyChar
+ {
+ get { return _keyChar; }
}
- public ConsoleModifiers Modifiers {
- get { return modifiers; }
+ public ConsoleModifiers Modifiers
+ {
+ get { return _mods; }
}
-
+
public override bool Equals (object value)
{
if (!(value is ConsoleKeyInfo))
return false;
+
return Equals ((ConsoleKeyInfo) value);
}
-
+
public static bool operator == (ConsoleKeyInfo a, ConsoleKeyInfo b)
{
return a.Equals (b);
}
-
+
public static bool operator != (ConsoleKeyInfo a, ConsoleKeyInfo b)
{
return !a.Equals (b);
}
-
+
public bool Equals (ConsoleKeyInfo obj)
{
- return key == obj.key && obj.keychar == keychar && obj.modifiers == modifiers;
+ return _key == obj._key && _keyChar == obj._keyChar && _mods == obj._mods;
}
-
+
public override int GetHashCode ()
{
- return key.GetHashCode () ^ keychar.GetHashCode () ^ modifiers.GetHashCode ();
+ return _key.GetHashCode () ^ _keyChar.GetHashCode () ^ _mods.GetHashCode ();
}
}
}
-
diff --git a/mcs/class/corlib/System/Convert.cs b/mcs/class/corlib/System/Convert.cs
index ae3b87120a..a17181f38b 100644
--- a/mcs/class/corlib/System/Convert.cs
+++ b/mcs/class/corlib/System/Convert.cs
@@ -1,12 +1,13 @@
//
// System.Convert.cs
//
-// Author:
+// Authors:
// Derek Holden (dholden@draper.com)
// Duncan Mak (duncan@ximian.com)
+// Marek Safar (marek.safar@gmail.com)
//
// (C) Ximian, Inc. http://www.ximian.com
-//
+// Copyright (C) 2013 Xamarin Inc (http://www.xamarin.com)
//
// System.Convert class. This was written word for word off the
// Library specification for System.Convert in the ECMA TC39 TG2
@@ -2528,6 +2529,7 @@ namespace System {
typeof (DateTime), // 16 TypeCode.DateTime
null, // 17 null.
typeof (String), // 18 TypeCode.String
+ typeof (Enum)
};
// Function to convert an object to another type and return
@@ -2561,67 +2563,69 @@ namespace System {
if (value.GetType () == conversionType)
return value;
- if (value is IConvertible) {
- IConvertible convertValue = (IConvertible) value;
+ IConvertible convertValue = value as IConvertible;
+ if (convertValue != null) {
if (conversionType == conversionTable[0]) // 0 Empty
throw new ArgumentNullException ();
- else if (conversionType == conversionTable[1]) // 1 TypeCode.Object
- return (object) value;
+ if (conversionType == conversionTable[1]) // 1 TypeCode.Object
+ return value;
- else if (conversionType == conversionTable[2]) // 2 TypeCode.DBNull
+ if (conversionType == conversionTable[2]) // 2 TypeCode.DBNull
throw new InvalidCastException (
"Cannot cast to DBNull, it's not IConvertible");
- else if (conversionType == conversionTable[3]) // 3 TypeCode.Boolean
- return (object) convertValue.ToBoolean (provider);
+ if (conversionType == conversionTable[3]) // 3 TypeCode.Boolean
+ return convertValue.ToBoolean (provider);
- else if (conversionType == conversionTable[4]) // 4 TypeCode.Char
- return (object) convertValue.ToChar (provider);
+ if (conversionType == conversionTable[4]) // 4 TypeCode.Char
+ return convertValue.ToChar (provider);
- else if (conversionType == conversionTable[5]) // 5 TypeCode.SByte
- return (object) convertValue.ToSByte (provider);
+ if (conversionType == conversionTable[5]) // 5 TypeCode.SByte
+ return convertValue.ToSByte (provider);
- else if (conversionType == conversionTable[6]) // 6 TypeCode.Byte
- return (object) convertValue.ToByte (provider);
+ if (conversionType == conversionTable[6]) // 6 TypeCode.Byte
+ return convertValue.ToByte (provider);
- else if (conversionType == conversionTable[7]) // 7 TypeCode.Int16
- return (object) convertValue.ToInt16 (provider);
+ if (conversionType == conversionTable[7]) // 7 TypeCode.Int16
+ return convertValue.ToInt16 (provider);
- else if (conversionType == conversionTable[8]) // 8 TypeCode.UInt16
- return (object) convertValue.ToUInt16 (provider);
+ if (conversionType == conversionTable[8]) // 8 TypeCode.UInt16
+ return convertValue.ToUInt16 (provider);
- else if (conversionType == conversionTable[9]) // 9 TypeCode.Int32
- return (object) convertValue.ToInt32 (provider);
+ if (conversionType == conversionTable[9]) // 9 TypeCode.Int32
+ return convertValue.ToInt32 (provider);
- else if (conversionType == conversionTable[10]) // 10 TypeCode.UInt32
- return (object) convertValue.ToUInt32 (provider);
+ if (conversionType == conversionTable[10]) // 10 TypeCode.UInt32
+ return convertValue.ToUInt32 (provider);
- else if (conversionType == conversionTable[11]) // 11 TypeCode.Int64
- return (object) convertValue.ToInt64 (provider);
+ if (conversionType == conversionTable[11]) // 11 TypeCode.Int64
+ return convertValue.ToInt64 (provider);
- else if (conversionType == conversionTable[12]) // 12 TypeCode.UInt64
- return (object) convertValue.ToUInt64 (provider);
+ if (conversionType == conversionTable[12]) // 12 TypeCode.UInt64
+ return convertValue.ToUInt64 (provider);
- else if (conversionType == conversionTable[13]) // 13 TypeCode.Single
- return (object) convertValue.ToSingle (provider);
+ if (conversionType == conversionTable[13]) // 13 TypeCode.Single
+ return convertValue.ToSingle (provider);
- else if (conversionType == conversionTable[14]) // 14 TypeCode.Double
- return (object) convertValue.ToDouble (provider);
+ if (conversionType == conversionTable[14]) // 14 TypeCode.Double
+ return convertValue.ToDouble (provider);
- else if (conversionType == conversionTable[15]) // 15 TypeCode.Decimal
- return (object) convertValue.ToDecimal (provider);
+ if (conversionType == conversionTable[15]) // 15 TypeCode.Decimal
+ return convertValue.ToDecimal (provider);
- else if (conversionType == conversionTable[16]) // 16 TypeCode.DateTime
- return (object) convertValue.ToDateTime (provider);
+ if (conversionType == conversionTable[16]) // 16 TypeCode.DateTime
+ return convertValue.ToDateTime (provider);
- else if (conversionType == conversionTable[18]) // 18 TypeCode.String
- return (object) convertValue.ToString (provider);
- else {
- if (try_target_to_type)
- return convertValue.ToType (conversionType, provider);
- }
+ if (conversionType == conversionTable[18]) // 18 TypeCode.String
+ return convertValue.ToString (provider);
+
+ if (conversionType == conversionTable[19] && value is Enum) // System.Enum
+ return value;
+
+ if (try_target_to_type)
+ return convertValue.ToType (conversionType, provider);
}
// Not in the conversion table
throw new InvalidCastException ((Locale.GetText (
diff --git a/mcs/class/corlib/System/Delegate.cs b/mcs/class/corlib/System/Delegate.cs
index aa4301d016..507153c421 100644
--- a/mcs/class/corlib/System/Delegate.cs
+++ b/mcs/class/corlib/System/Delegate.cs
@@ -527,7 +527,7 @@ namespace System
return source;
if (source.GetType () != value.GetType ())
- throw new ArgumentException ("Delegate type mismatch");
+ throw new ArgumentException (Locale.GetText ("Incompatible Delegate Types. First is {0} second is {1}.", source.GetType ().FullName, value.GetType ().FullName));
return source.RemoveImpl (value);
}
diff --git a/mcs/class/corlib/System/Enum.cs b/mcs/class/corlib/System/Enum.cs
index c16e604d97..ecf2ed1898 100644
--- a/mcs/class/corlib/System/Enum.cs
+++ b/mcs/class/corlib/System/Enum.cs
@@ -278,9 +278,8 @@ namespace System
{
if (targetType == null)
throw new ArgumentNullException ("targetType");
- if (targetType == typeof (string))
- return ToString (provider);
- return Convert.ToType (Value, targetType, provider, false);
+
+ return Convert.ToType (this, targetType, provider, false);
}
ushort IConvertible.ToUInt16 (IFormatProvider provider)
diff --git a/mcs/class/corlib/System/Environment.cs b/mcs/class/corlib/System/Environment.cs
index d1b4015c03..13d63ccc12 100644
--- a/mcs/class/corlib/System/Environment.cs
+++ b/mcs/class/corlib/System/Environment.cs
@@ -56,7 +56,7 @@ namespace System {
* of icalls, do not require an increment.
*/
#pragma warning disable 169
- private const int mono_corlib_version = 110;
+ private const int mono_corlib_version = 111;
#pragma warning restore 169
[ComVisible (true)]
diff --git a/mcs/class/corlib/System/MulticastDelegate.cs b/mcs/class/corlib/System/MulticastDelegate.cs
index ab7583652c..0550ff8284 100644
--- a/mcs/class/corlib/System/MulticastDelegate.cs
+++ b/mcs/class/corlib/System/MulticastDelegate.cs
@@ -43,19 +43,17 @@ namespace System
[StructLayout (LayoutKind.Sequential)]
public abstract class MulticastDelegate : Delegate
{
- private MulticastDelegate prev;
- private MulticastDelegate kpm_next;
+ MulticastDelegate prev;
+ MulticastDelegate kpm_next;
protected MulticastDelegate (object target, string method)
: base (target, method)
{
- prev = null;
}
protected MulticastDelegate (Type target, string method)
: base (target, method)
{
- prev = null;
}
public override void GetObjectData (SerializationInfo info, StreamingContext context)
@@ -72,9 +70,6 @@ namespace System
return base.DynamicInvokeImpl (args);
}
- internal bool HasSingleTarget {
- get { return prev == null; }
- }
// <remarks>
// Equals: two multicast delegates are equal if their base is equal
// and their invocations list is equal.
diff --git a/mcs/class/corlib/System/NumberFormatter.cs b/mcs/class/corlib/System/NumberFormatter.cs
index 4f948aaf38..dc0fb5a1e1 100644
--- a/mcs/class/corlib/System/NumberFormatter.cs
+++ b/mcs/class/corlib/System/NumberFormatter.cs
@@ -557,9 +557,7 @@ namespace System
private void Resize (int len)
{
- char[] newBuf = new char [len];
- Array.Copy (_cbuf, newBuf, _ind);
- _cbuf = newBuf;
+ Array.Resize (ref _cbuf, len);
}
private void Append (char c)
@@ -783,6 +781,7 @@ namespace System
threadNumberFormatter = null;
if (res == null)
return new NumberFormatter (Thread.CurrentThread);
+ res.CurrentCulture = Thread.CurrentThread.CurrentCulture;
return res;
}
@@ -791,12 +790,6 @@ namespace System
threadNumberFormatter = this;
}
- internal static void SetThreadCurrentCulture (CultureInfo culture)
- {
- if (threadNumberFormatter != null)
- threadNumberFormatter.CurrentCulture = culture;
- }
-
public static string NumberToString (string format, sbyte value, IFormatProvider fp)
{
NumberFormatter inst = GetInstance();
diff --git a/mcs/class/corlib/System/Random.cs b/mcs/class/corlib/System/Random.cs
index 1f84216ffe..0bf5c74627 100644
--- a/mcs/class/corlib/System/Random.cs
+++ b/mcs/class/corlib/System/Random.cs
@@ -4,13 +4,12 @@
// Authors:
// Bob Smith (bob@thestuff.net)
// Ben Maurer (bmaurer@users.sourceforge.net)
+// Sebastien Pouliot <sebastien@xamarin.com>
//
// (C) 2001 Bob Smith. http://www.thestuff.net
// (C) 2003 Ben Maurer
-//
-
-//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright 2013 Xamarin Inc. (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -39,12 +38,11 @@ namespace System
[ComVisible (true)]
public class Random
{
- const int MBIG = int.MaxValue;
- const int MSEED = 161803398;
+ uint x;
+ uint y;
+ uint z;
+ uint c;
- int inext, inextp;
- int [] SeedArray = new int [56];
-
public Random ()
: this (Environment.TickCount)
{
@@ -52,75 +50,28 @@ namespace System
public Random (int Seed)
{
- int ii;
- int mj, mk;
-
- // Numerical Recipes in C online @ http://www.library.cornell.edu/nr/bookcpdf/c7-1.pdf
-
- // Math.Abs throws on Int32.MinValue, so we need to work around that case.
- // Fixes: 605797
- if (Seed == Int32.MinValue)
- mj = MSEED - Math.Abs (Int32.MinValue + 1);
- else
- mj = MSEED - Math.Abs (Seed);
-
- SeedArray [55] = mj;
- mk = 1;
- for (int i = 1; i < 55; i++) { // [1, 55] is special (Knuth)
- ii = (21 * i) % 55;
- SeedArray [ii] = mk;
- mk = mj - mk;
- if (mk < 0)
- mk += MBIG;
- mj = SeedArray [ii];
- }
- for (int k = 1; k < 5; k++) {
- for (int i = 1; i < 56; i++) {
- SeedArray [i] -= SeedArray [1 + (i + 30) % 55];
- if (SeedArray [i] < 0)
- SeedArray [i] += MBIG;
- }
- }
- inext = 0;
- inextp = 31;
- }
-
- protected virtual double Sample ()
- {
- int retVal;
-
- if (++inext >= 56) inext = 1;
- if (++inextp >= 56) inextp = 1;
-
- retVal = SeedArray [inext] - SeedArray [inextp];
-
- if (retVal < 0)
- retVal += MBIG;
-
- SeedArray [inext] = retVal;
-
- return retVal * (1.0 / MBIG);
- }
-
- public virtual int Next ()
- {
- return (int)(Sample () * int.MaxValue);
+ x = (uint) Seed;
+ y = (uint) 987654321;
+ z = (uint) 43219876;
+ c = (uint) 6543217;
}
- public virtual int Next (int maxValue)
+ uint JKiss ()
{
- if (maxValue < 0)
- throw new ArgumentOutOfRangeException(Locale.GetText (
- "Max value is less than min value."));
-
- return (int)(Sample () * maxValue);
+ x = 314527869 * x + 1234567;
+ y ^= y << 5;
+ y ^= y >> 7;
+ y ^= y << 22;
+ ulong t = ((ulong) 4294584393 * z + c);
+ c = (uint) (t >> 32);
+ z = (uint) t;
+ return (x + y + z);
}
public virtual int Next (int minValue, int maxValue)
{
if (minValue > maxValue)
- throw new ArgumentOutOfRangeException (Locale.GetText (
- "Min value is greater than max value."));
+ throw new ArgumentOutOfRangeException ("Maximum value is less than minimal value.");
// special case: a difference of one (or less) will always return the minimum
// e.g. -1,-1 or -1,0 will always return -1
@@ -128,7 +79,28 @@ namespace System
if (diff <= 1)
return minValue;
- return (int)((uint)(Sample () * diff) + minValue);
+ return minValue + ((int) (JKiss () % diff));
+ }
+
+ public virtual int Next (int maxValue)
+ {
+ if (maxValue < 0)
+ throw new ArgumentOutOfRangeException ("Maximum value is less than minimal value.");
+
+ return maxValue > 0 ? (int)(JKiss () % maxValue) : 0;
+ }
+
+ public virtual int Next ()
+ {
+ // returns a non-negative, [0 - Int32.MacValue], random number
+ // but we want to avoid calls to Math.Abs (call cost and branching cost it requires)
+ // and the fact it would throw for Int32.MinValue (so roughly 1 time out of 2^32)
+ int random = (int) JKiss ();
+ while (random == Int32.MinValue)
+ random = (int) JKiss ();
+ int mask = random >> 31;
+ random ^= mask;
+ return random + (mask & 1);
}
public virtual void NextBytes (byte [] buffer)
@@ -136,14 +108,39 @@ namespace System
if (buffer == null)
throw new ArgumentNullException ("buffer");
- for (int i = 0; i < buffer.Length; i++) {
- buffer [i] = (byte)(Sample () * (byte.MaxValue + 1));
+ // each random `int` can fill 4 bytes
+ int p = 0;
+ uint random;
+ for (int i = 0; i < (buffer.Length >> 2); i++) {
+ random = JKiss ();
+ buffer [p++] = (byte) (random >> 24);
+ buffer [p++] = (byte) (random >> 16);
+ buffer [p++] = (byte) (random >> 8);
+ buffer [p++] = (byte) random;
+ }
+ if (p == buffer.Length)
+ return;
+
+ // complete the array
+ random = JKiss ();
+ while (p < buffer.Length) {
+ buffer [p++] = (byte) random;
+ random >>= 8;
}
}
public virtual double NextDouble ()
{
- return this.Sample ();
+ // return a double value between [0,1]
+ return Sample ();
+ }
+
+ protected virtual double Sample ()
+ {
+ // a single 32 bits random value is not enough to create a random double value
+ uint a = JKiss () >> 6; // Upper 26 bits
+ uint b = JKiss () >> 5; // Upper 27 bits
+ return (a * 134217728.0 + b) / 9007199254740992.0;
}
}
-}
+} \ No newline at end of file
diff --git a/mcs/class/corlib/System/String.cs b/mcs/class/corlib/System/String.cs
index d30735f9bd..1d32ab6d41 100644
--- a/mcs/class/corlib/System/String.cs
+++ b/mcs/class/corlib/System/String.cs
@@ -2710,9 +2710,7 @@ namespace System
if (values == null)
throw new ArgumentNullException ("values");
- var stringList = new List<string> ();
- foreach (var v in values)
- stringList.Add (v);
+ var stringList = new List<string> (values);
return JoinUnchecked (separator, stringList.ToArray (), 0, stringList.Count);
}
@@ -2743,11 +2741,13 @@ namespace System
if (values == null)
throw new ArgumentNullException ("values");
- var stringList = new List<string> ();
- foreach (var v in values)
- stringList.Add (v.ToString ());
+ var stringList = values as IList<T> ?? new List<T> (values);
+ var strCopy = new string [stringList.Count];
+ int i = 0;
+ foreach (var v in stringList)
+ strCopy [i++] = v.ToString ();
- return JoinUnchecked (separator, stringList.ToArray (), 0, stringList.Count);
+ return JoinUnchecked (separator, strCopy, 0, strCopy.Length);
}
public static bool IsNullOrWhiteSpace (string value)
diff --git a/mcs/class/corlib/System/TimeZone.cs b/mcs/class/corlib/System/TimeZone.cs
index 316e99ce44..5e11d8d53d 100644
--- a/mcs/class/corlib/System/TimeZone.cs
+++ b/mcs/class/corlib/System/TimeZone.cs
@@ -357,12 +357,22 @@ namespace System
if (time.Kind == DateTimeKind.Utc)
return TimeSpan.Zero;
- if (IsDaylightSavingTime (time))
+ if (IsDaylightSavingTime (time) && !IsAmbiguousTime (time))
return utcOffsetWithDLS;
return utcOffsetWithOutDLS;
}
+ private bool IsAmbiguousTime (DateTime time)
+ {
+ if (time.Kind == DateTimeKind.Utc)
+ return false;
+
+ DaylightTime changes = GetDaylightChanges (time.Year);
+
+ return time < changes.End && time >= changes.End - changes.Delta;
+ }
+
void IDeserializationCallback.OnDeserialization (object sender)
{
OnDeserialization (null);
diff --git a/mcs/class/corlib/System/Tuples.cs b/mcs/class/corlib/System/Tuples.cs
index ac15adfec6..a9631dbbda 100644
--- a/mcs/class/corlib/System/Tuples.cs
+++ b/mcs/class/corlib/System/Tuples.cs
@@ -48,23 +48,20 @@ namespace System
this.item7 = item7;
this.rest = rest;
- bool ok = true;
- if (!typeof (TRest).IsGenericType)
- ok = false;
- if (ok) {
- Type t = typeof (TRest).GetGenericTypeDefinition ();
- if (!(t == typeof (Tuple<>) || t == typeof (Tuple<,>) || t == typeof (Tuple<,,>) || t == typeof (Tuple<,,,>) || t == typeof (Tuple<,,,,>) || t == typeof (Tuple <,,,,,>) || t == typeof (Tuple<,,,,,,>) || t == typeof (Tuple<,,,,,,,>)))
- ok = false;
- }
- if (!ok)
+ if (!(rest is ITuple))
throw new ArgumentException ("rest", "The last element of an eight element tuple must be a Tuple.");
}
}
+ interface ITuple
+ {
+ string ToString ();
+ }
+
/* The rest is generated by the script at the bottom */
[Serializable]
- public class Tuple<T1> : IStructuralEquatable, IStructuralComparable, IComparable
+ public class Tuple<T1> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple
{
T1 item1;
@@ -117,14 +114,19 @@ namespace System
return comparer.GetHashCode (item1);
}
+ string ITuple.ToString ()
+ {
+ return String.Format ("{0}", item1);
+ }
+
public override string ToString ()
{
- return String.Format ("({0})", item1);
+ return "(" + ((ITuple) this).ToString () + ")";
}
}
[Serializable]
- public class Tuple<T1, T2> : IStructuralEquatable, IStructuralComparable, IComparable
+ public class Tuple<T1, T2> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple
{
T1 item1;
T2 item2;
@@ -183,19 +185,25 @@ namespace System
int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
{
- int h = comparer.GetHashCode (item1);
- h = (h << 5) - h + comparer.GetHashCode (item2);
- return h;
+ int h0;
+ h0 = comparer.GetHashCode (item1);
+ h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item2);
+ return h0;
+ }
+
+ string ITuple.ToString ()
+ {
+ return String.Format ("{0}, {1}", item1, item2);
}
public override string ToString ()
{
- return String.Format ("({0}, {1})", item1, item2);
+ return "(" + ((ITuple) this).ToString () + ")";
}
}
[Serializable]
- public class Tuple<T1, T2, T3> : IStructuralEquatable, IStructuralComparable, IComparable
+ public class Tuple<T1, T2, T3> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple
{
T1 item1;
T2 item2;
@@ -263,20 +271,26 @@ namespace System
int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
{
- int h = comparer.GetHashCode (item1);
- h = (h << 5) - h + comparer.GetHashCode (item2);
- h = (h << 5) - h + comparer.GetHashCode (item3);
- return h;
+ int h0;
+ h0 = comparer.GetHashCode (item1);
+ h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item2);
+ h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item3);
+ return h0;
+ }
+
+ string ITuple.ToString ()
+ {
+ return String.Format ("{0}, {1}, {2}", item1, item2, item3);
}
public override string ToString ()
{
- return String.Format ("({0}, {1}, {2})", item1, item2, item3);
+ return "(" + ((ITuple) this).ToString () + ")";
}
}
[Serializable]
- public class Tuple<T1, T2, T3, T4> : IStructuralEquatable, IStructuralComparable, IComparable
+ public class Tuple<T1, T2, T3, T4> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple
{
T1 item1;
T2 item2;
@@ -353,21 +367,28 @@ namespace System
int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
{
- int h = comparer.GetHashCode (item1);
- h = (h << 5) - h + comparer.GetHashCode (item2);
- h = (h << 5) - h + comparer.GetHashCode (item3);
- h = (h << 5) - h + comparer.GetHashCode (item4);
- return h;
+ int h0, h1;
+ h0 = comparer.GetHashCode (item1);
+ h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item2);
+ h1 = comparer.GetHashCode (item3);
+ h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item4);
+ h0 = (h0 << 5) + h0 ^ h1;
+ return h0;
+ }
+
+ string ITuple.ToString ()
+ {
+ return String.Format ("{0}, {1}, {2}, {3}", item1, item2, item3, item4);
}
public override string ToString ()
{
- return String.Format ("({0}, {1}, {2}, {3})", item1, item2, item3, item4);
+ return "(" + ((ITuple) this).ToString () + ")";
}
}
[Serializable]
- public class Tuple<T1, T2, T3, T4, T5> : IStructuralEquatable, IStructuralComparable, IComparable
+ public class Tuple<T1, T2, T3, T4, T5> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple
{
T1 item1;
T2 item2;
@@ -453,22 +474,29 @@ namespace System
int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
{
- int h = comparer.GetHashCode (item1);
- h = (h << 5) - h + comparer.GetHashCode (item2);
- h = (h << 5) - h + comparer.GetHashCode (item3);
- h = (h << 5) - h + comparer.GetHashCode (item4);
- h = (h << 5) - h + comparer.GetHashCode (item5);
- return h;
+ int h0, h1;
+ h0 = comparer.GetHashCode (item1);
+ h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item2);
+ h1 = comparer.GetHashCode (item3);
+ h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item4);
+ h0 = (h0 << 5) + h0 ^ h1;
+ h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item5);
+ return h0;
+ }
+
+ string ITuple.ToString ()
+ {
+ return String.Format ("{0}, {1}, {2}, {3}, {4}", item1, item2, item3, item4, item5);
}
public override string ToString ()
{
- return String.Format ("({0}, {1}, {2}, {3}, {4})", item1, item2, item3, item4, item5);
+ return "(" + ((ITuple) this).ToString () + ")";
}
}
[Serializable]
- public class Tuple<T1, T2, T3, T4, T5, T6> : IStructuralEquatable, IStructuralComparable, IComparable
+ public class Tuple<T1, T2, T3, T4, T5, T6> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple
{
T1 item1;
T2 item2;
@@ -563,23 +591,31 @@ namespace System
int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
{
- int h = comparer.GetHashCode (item1);
- h = (h << 5) - h + comparer.GetHashCode (item2);
- h = (h << 5) - h + comparer.GetHashCode (item3);
- h = (h << 5) - h + comparer.GetHashCode (item4);
- h = (h << 5) - h + comparer.GetHashCode (item5);
- h = (h << 5) - h + comparer.GetHashCode (item6);
- return h;
+ int h0, h1;
+ h0 = comparer.GetHashCode (item1);
+ h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item2);
+ h1 = comparer.GetHashCode (item3);
+ h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item4);
+ h0 = (h0 << 5) + h0 ^ h1;
+ h1 = comparer.GetHashCode (item5);
+ h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item6);
+ h0 = (h0 << 5) + h0 ^ h1;
+ return h0;
+ }
+
+ string ITuple.ToString ()
+ {
+ return String.Format ("{0}, {1}, {2}, {3}, {4}, {5}", item1, item2, item3, item4, item5, item6);
}
public override string ToString ()
{
- return String.Format ("({0}, {1}, {2}, {3}, {4}, {5})", item1, item2, item3, item4, item5, item6);
+ return "(" + ((ITuple) this).ToString () + ")";
}
}
[Serializable]
- public class Tuple<T1, T2, T3, T4, T5, T6, T7> : IStructuralEquatable, IStructuralComparable, IComparable
+ public class Tuple<T1, T2, T3, T4, T5, T6, T7> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple
{
T1 item1;
T2 item2;
@@ -683,24 +719,32 @@ namespace System
int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
{
- int h = comparer.GetHashCode (item1);
- h = (h << 5) - h + comparer.GetHashCode (item2);
- h = (h << 5) - h + comparer.GetHashCode (item3);
- h = (h << 5) - h + comparer.GetHashCode (item4);
- h = (h << 5) - h + comparer.GetHashCode (item5);
- h = (h << 5) - h + comparer.GetHashCode (item6);
- h = (h << 5) - h + comparer.GetHashCode (item7);
- return h;
+ int h0, h1;
+ h0 = comparer.GetHashCode (item1);
+ h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item2);
+ h1 = comparer.GetHashCode (item3);
+ h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item4);
+ h0 = (h0 << 5) + h0 ^ h1;
+ h1 = comparer.GetHashCode (item5);
+ h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item6);
+ h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item7);
+ h0 = (h0 << 5) + h0 ^ h1;
+ return h0;
+ }
+
+ string ITuple.ToString ()
+ {
+ return String.Format ("{0}, {1}, {2}, {3}, {4}, {5}, {6}", item1, item2, item3, item4, item5, item6, item7);
}
public override string ToString ()
{
- return String.Format ("({0}, {1}, {2}, {3}, {4}, {5}, {6})", item1, item2, item3, item4, item5, item6, item7);
+ return "(" + ((ITuple) this).ToString () + ")";
}
}
[Serializable]
- public partial class Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> : IStructuralEquatable, IStructuralComparable, IComparable
+ public partial class Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple
{
T1 item1;
T2 item2;
@@ -801,20 +845,29 @@ namespace System
int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
{
- int h = comparer.GetHashCode (item1);
- h = (h << 5) - h + comparer.GetHashCode (item2);
- h = (h << 5) - h + comparer.GetHashCode (item3);
- h = (h << 5) - h + comparer.GetHashCode (item4);
- h = (h << 5) - h + comparer.GetHashCode (item5);
- h = (h << 5) - h + comparer.GetHashCode (item6);
- h = (h << 5) - h + comparer.GetHashCode (item7);
- h = (h << 5) - h + comparer.GetHashCode (rest);
- return h;
+ int h0, h1, h2;
+ h0 = comparer.GetHashCode (item1);
+ h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item2);
+ h1 = comparer.GetHashCode (item3);
+ h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item4);
+ h0 = (h0 << 5) + h0 ^ h1;
+ h1 = comparer.GetHashCode (item5);
+ h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item6);
+ h2 = comparer.GetHashCode (item7);
+ h2 = (h2 << 5) + h2 ^ comparer.GetHashCode (rest);
+ h1 = (h1 << 5) + h1 ^ h2;
+ h0 = (h0 << 5) + h0 ^ h1;
+ return h0;
+ }
+
+ string ITuple.ToString ()
+ {
+ return String.Format ("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", item1, item2, item3, item4, item5, item6, item7, ((ITuple)rest).ToString ());
}
public override string ToString ()
{
- return String.Format ("({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7})", item1, item2, item3, item4, item5, item6, item7, rest);
+ return "(" + ((ITuple) this).ToString () + ")";
}
}
@@ -840,11 +893,11 @@ public class TupleGen
Console.WriteLine ("\t[Serializable]");
Console.Write ("\tpublic {0}class ", arity < 8 ? null : "partial ");
Console.Write (type_name);
- Console.WriteLine (" : IStructuralEquatable, IStructuralComparable, IComparable");
+ Console.WriteLine (" : IStructuralEquatable, IStructuralComparable, IComparable, ITuple");
Console.WriteLine ("\t{");
for (int i = 1; i <= arity; ++i)
Console.WriteLine ("\t\t{0} {1};", GetItemTypeName (i), GetItemName (i));
-
+
if (arity < 8) {
Console.WriteLine ();
Console.Write ("\t\tpublic Tuple (");
@@ -874,17 +927,17 @@ public class TupleGen
Console.WriteLine ("\t\t{");
Console.WriteLine ("\t\t\treturn ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);");
Console.WriteLine ("\t\t}");
-
+
Console.WriteLine ();
Console.WriteLine ("\t\tint IStructuralComparable.CompareTo (object other, IComparer comparer)");
Console.WriteLine ("\t\t{");
Console.WriteLine ("\t\t\tvar t = other as {0};", type_name);
Console.WriteLine ("\t\t\tif (t == null) {");
Console.WriteLine ("\t\t\t\tif (other == null) return 1;");
- Console.WriteLine ("\t\t\t\tthrow new ArgumentException ("other");");
+ Console.WriteLine ("\t\t\t\tthrow new ArgumentException (\"other\");");
Console.WriteLine ("\t\t\t}");
Console.WriteLine ();
-
+
for (int i = 1; i < arity; ++i) {
Console.Write ("\t\t\t");
if (i == 1)
@@ -894,14 +947,14 @@ public class TupleGen
Console.WriteLine ("\t\t\tif (res != 0) return res;");
}
Console.WriteLine ("\t\t\treturn comparer.Compare ({0}, t.{0});", GetItemName (arity));
- Console.WriteLine ("\t\t}");
-
+ Console.WriteLine ("\t\t}");
+
Console.WriteLine ();
Console.WriteLine ("\t\tpublic override bool Equals (object obj)");
Console.WriteLine ("\t\t{");
Console.WriteLine ("\t\t\treturn ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);");
Console.WriteLine ("\t\t}");
-
+
Console.WriteLine ();
Console.WriteLine ("\t\tbool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)");
Console.WriteLine ("\t\t{");
@@ -910,7 +963,7 @@ public class TupleGen
Console.WriteLine ("\t\t\t\treturn false;");
Console.WriteLine ();
Console.Write ("\t\t\treturn");
-
+
for (int i = 1; i <= arity; ++i) {
if (i == 1)
Console.Write (" ");
@@ -924,49 +977,91 @@ public class TupleGen
Console.WriteLine (";");
}
Console.WriteLine ("\t\t}");
-
+
Console.WriteLine ();
Console.WriteLine ("\t\tpublic override int GetHashCode ()");
Console.WriteLine ("\t\t{");
Console.WriteLine ("\t\t\treturn ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);");
Console.WriteLine ("\t\t}");
-
+
Console.WriteLine ();
Console.WriteLine ("\t\tint IStructuralEquatable.GetHashCode (IEqualityComparer comparer)");
Console.WriteLine ("\t\t{");
if (arity == 1) {
Console.WriteLine ("\t\t\treturn comparer.GetHashCode ({0});", GetItemName (arity));
} else {
- Console.WriteLine ("\t\t\tint h = comparer.GetHashCode ({0});", GetItemName (1));
- for (int i = 2; i <= arity; ++i)
- Console.WriteLine ("\t\t\th = (h << 5) - h + comparer.GetHashCode ({0});", GetItemName (i));
- Console.WriteLine ("\t\t\treturn h;");
+ int varnum = IntLog2 (arity);
+ Console.Write ("\t\t\tint h0");
+ for (int i = 1; i < varnum; ++i)
+ Console.Write (", h{0}", i);
+ Console.WriteLine (";");
+
+ WriteHash (0, 1, arity);
+
+ Console.WriteLine ("\t\t\treturn h0;");
}
Console.WriteLine ("\t\t}");
Console.WriteLine ();
- Console.WriteLine ("\t\tpublic override string ToString ()");
+ Console.WriteLine ("\t\tstring ITuple.ToString ()");
Console.WriteLine ("\t\t{");
- Console.Write ("\t\t\treturn String.Format (\"(");
+ Console.Write ("\t\t\treturn String.Format (\"");
for (int i = 1; i <= arity; ++i) {
Console.Write ("{" + (i - 1) + "}");
if (i < arity)
Console.Write (", ");
}
- Console.Write (")\", ");
+ Console.Write ("\", ");
for (int i = 1; i <= arity; ++i) {
- Console.Write (GetItemName (i));
+ var item_name = GetItemName (i);
+ Console.Write (i == 8 ? "((ITuple){0}).ToString ()" : "{0}", item_name);
if (i < arity)
Console.Write (", ");
}
Console.WriteLine (");");
Console.WriteLine ("\t\t}");
+ Console.WriteLine ();
+ Console.WriteLine ("\t\tpublic override string ToString ()");
+ Console.WriteLine ("\t\t{");
+ Console.WriteLine ("\t\t\treturn \"(\" + ((ITuple) this).ToString () + \")\";");
+ Console.WriteLine ("\t\t}");
+
Console.WriteLine ("\t}\n");
}
}
+ static int IntLog2 (int n)
+ {
+ int r = -1;
+
+ while (n != 0) {
+ n >>= 1;
+ r++;
+ }
+
+ return r;
+ }
+
+ static void WriteHash (int destVar, int start, int count)
+ {
+ if (count == 1) {
+ Console.WriteLine ("\t\t\th{0} = comparer.GetHashCode ({1});", destVar, GetItemName (start));
+ } else {
+ int subCount = 1 << IntLog2 (count - 1);
+ WriteHash (destVar, start, subCount);
+ start += subCount;
+ count -= subCount;
+ if (count == 1) {
+ Console.WriteLine ("\t\t\th{0} = (h{0} << 5) + h{0} ^ comparer.GetHashCode ({1});", destVar, GetItemName (start));
+ } else {
+ WriteHash (destVar + 1, start, count);
+ Console.WriteLine ("\t\t\th{0} = (h{0} << 5) + h{0} ^ h{1};", destVar, destVar + 1);
+ }
+ }
+ }
+
static string GetTypeName (int arity)
{
StringBuilder sb = new StringBuilder ();
@@ -977,19 +1072,20 @@ public class TupleGen
sb.Append (", ");
}
sb.Append (">");
-
+
return sb.ToString ();
}
-
+
static string GetItemName (int arity)
{
return arity < 8 ? "item" + arity.ToString () : "rest";
}
-
+
static string GetItemTypeName (int arity)
{
return arity < 8 ? "T" + arity.ToString () : "TRest";
}
}
+
#endif