-Fixed DateTimeZoneHandling not being used when writing DateTime dictionary keys

-Buffer pooling fixes
-Improved date parsing performance
This commit is contained in:
James Newton-King
2015-11-14 15:22:59 +13:00
parent f3822513df
commit a3eb2d596c
16 changed files with 689 additions and 227 deletions
@@ -23,6 +23,8 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
using System;
namespace Newtonsoft.Json.Utilities
{
internal struct StringReference
@@ -31,6 +33,11 @@ namespace Newtonsoft.Json.Utilities
private readonly int _startIndex;
private readonly int _length;
public char this[int i]
{
get { return _chars[i]; }
}
public char[] Chars
{
get { return _chars; }
@@ -58,4 +65,64 @@ namespace Newtonsoft.Json.Utilities
return new string(_chars, _startIndex, _length);
}
}
internal static class StringReferenceExtensions
{
public static int IndexOf(this StringReference s, char c)
{
return IndexOf(s, c, 0, 0);
}
public static int IndexOf(this StringReference s, char c, int startIndex, int length)
{
int index = Array.IndexOf(s.Chars, c, s.StartIndex + startIndex, length);
if (index == -1)
{
return -1;
}
return index - s.StartIndex;
}
public static bool StartsWith(this StringReference s, string text)
{
if (text.Length > s.Length)
{
return false;
}
char[] chars = s.Chars;
for (int i = 0; i < text.Length; i++)
{
if (text[i] != chars[i + s.StartIndex])
{
return false;
}
}
return true;
}
public static bool EndsWith(this StringReference s, string text)
{
if (text.Length > s.Length)
{
return false;
}
char[] chars = s.Chars;
int start = s.StartIndex + s.Length - text.Length;
for (int i = 0; i < text.Length; i++)
{
if (text[i] != chars[i + start])
{
return false;
}
}
return true;
}
}
}