-Fixed DateTimeZoneHandling not being used when writing DateTime dictionary keys
-Buffer pooling fixes -Improved date parsing performance
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user