Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ private void Initialize(FileUnit sourceFile)
}
}

int pathEndIndex = SourceFileInfo.RelativeSourceFilePath.LastIndexOf(string.Empty + Path.DirectorySeparatorChar, StringComparison.Ordinal);
int pathEndIndex = SourceFileInfo.RelativeSourceFilePath.LastIndexOf(Path.DirectorySeparatorChar);
string targetPath = TargetPath + SourceFileInfo.RelativeSourceFilePath.Substring(0, pathEndIndex + 1);

// Create if not already exists
Expand Down Expand Up @@ -716,7 +716,7 @@ private SourceFileInfo OnSourceFileResolve(FileUnit file)

if (sourceFileInfo.IsXamlFile)
{
int fileExtIndex = file.Path.LastIndexOf(DOT, StringComparison.Ordinal);
int fileExtIndex = file.Path.LastIndexOf(DOTCHAR);

sourceFileInfo.RelativeSourceFilePath = file.Path.Substring(0, fileExtIndex);
}
Expand Down Expand Up @@ -1420,7 +1420,7 @@ private string GetFullClassName(string ns, string className)
internal void ValidateFullSubClassName(ref string subClassFullName)
{
bool isValid = false;
int index = subClassFullName.LastIndexOf(DOT, StringComparison.Ordinal);
int index = subClassFullName.LastIndexOf(DOTCHAR);

if (index > 0)
{
Expand Down Expand Up @@ -1449,7 +1449,7 @@ private bool CrackClassName(ref string className, out string ns)
if (className.Length > 0)
{
// Split the Namespace
int index = className.LastIndexOf(DOT, StringComparison.Ordinal);
int index = className.LastIndexOf(DOTCHAR);

if (index > 0)
{
Expand Down Expand Up @@ -2323,7 +2323,7 @@ private static CodeTypeReference GenerateConstructedTypeReference(Type t, string

// NOTE: Remove when CodeDom is fixed to understand mangled generic names.
genericName = t.FullName;
int bang = genericName.IndexOf(GENERIC_DELIMITER, StringComparison.Ordinal);
int bang = genericName.IndexOf(GENERIC_DELIMITER);
if (bang > 0)
{
genericName = genericName.Substring(0, bang);
Expand Down Expand Up @@ -2366,7 +2366,7 @@ private static CodeTypeReference GenerateConstructedTypeReference(Type t, string

// NOTE: Remove when CodeDom is fixed to understand mangled generic names.
string genericName = t.Namespace + DOT + t.Name;
int bang = genericName.IndexOf(GENERIC_DELIMITER, StringComparison.Ordinal);
int bang = genericName.IndexOf(GENERIC_DELIMITER);
if (bang > 0)
{
genericName = genericName.Substring(0, bang);
Expand Down Expand Up @@ -3542,7 +3542,7 @@ internal string SubClass
private const string ANONYMOUS_ENTRYCLASS_PREFIX = "Generated";
private const string DEFINITION_PREFIX = "x";
private const char COMMA = ',';
private const string GENERIC_DELIMITER = "`";
private const char GENERIC_DELIMITER = '`';
internal const char DOTCHAR = '.';
internal const string DOT = ".";
internal const string CODETAG = "Code";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ public override void WriteDefAttribute(XamlDefAttributeNode xamlDefAttributeNode
{
if (_class == MarkupCompiler.DOT)
{
int index = xamlDefAttributeNode.Value.LastIndexOf(MarkupCompiler.DOT, StringComparison.Ordinal);
int index = xamlDefAttributeNode.Value.LastIndexOf(MarkupCompiler.DOTCHAR);
ThrowException(SRID.InvalidClassName,
MarkupCompiler.DefinitionNSPrefix,
CLASS,
Expand Down Expand Up @@ -869,7 +869,7 @@ public override void WriteDefAttribute(XamlDefAttributeNode xamlDefAttributeNode
{
if (_subClass == MarkupCompiler.DOT)
{
int index = xamlDefAttributeNode.Value.LastIndexOf(MarkupCompiler.DOT, StringComparison.Ordinal);
int index = xamlDefAttributeNode.Value.LastIndexOf(MarkupCompiler.DOTCHAR);
ThrowException(SRID.InvalidClassName,
MarkupCompiler.DefinitionNSPrefix,
SUBCLASS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ internal static string GenerateCacheForFileList(ITaskItem[] fileItemList)

for (int i = 0; i < iCount; i++)
{
iHashCode += fileItemList[i].ItemSpec.GetHashCode();
iHashCode += GetNonRandomizedHashCode(fileItemList[i].ItemSpec);
}

StringBuilder sb = new StringBuilder();
Expand Down Expand Up @@ -251,6 +251,49 @@ private static string GenerateStringFromFileNames(ITaskItem[] fileItemList)
return fileNames;
}

//
// Generates a stable hash code value for strings.
// In .NET Core the hash values for the same string can be different between
// subsequent program runs and cannot be used for caching here.
// Copied from String.Comparison.cs
//
private static unsafe int GetNonRandomizedHashCode(string str)
{
fixed (char* src = str)
{
Debug.Assert(src[str.Length] == '\0', "src[str.Length] == '\\0'");
Debug.Assert(((int)src) % 4 == 0, "Managed string should start at 4 bytes boundary");

uint hash1 = (5381 << 16) + 5381;
uint hash2 = hash1;

uint* ptr = (uint*)src;
int length = str.Length;

while (length > 2)
{
length -= 4;
// Where length is 4n-1 (e.g. 3,7,11,15,19) this additionally consumes the null terminator
hash1 = (RotateLeft(hash1, 5) + hash1) ^ ptr[0];
hash2 = (RotateLeft(hash2, 5) + hash2) ^ ptr[1];
ptr += 2;
}

if (length > 0)
{
// Where length is 4n-3 (e.g. 1,5,9,13,17) this additionally consumes the null terminator
hash2 = (RotateLeft(hash2, 5) + hash2) ^ ptr[0];
}

return (int)(hash1 + (hash2 * 1566083941));
}
}

private static uint RotateLeft(uint value, int offset)
{
return (value << offset) | (value >> (32 - offset));
}

#endregion

#region internal properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ private void OnSourceFileResolve(Object sender, SourceFileResolveEventArgs e)
//
// For Xaml Source file, we need to remove the .xaml extension part.
//
int fileExtIndex = newRelativeFilePath.LastIndexOf(MarkupCompiler.DOT, StringComparison.Ordinal);
int fileExtIndex = newRelativeFilePath.LastIndexOf(MarkupCompiler.DOTCHAR);
newRelativeFilePath = newRelativeFilePath.Substring(0, fileExtIndex);
}

Expand Down Expand Up @@ -413,7 +413,7 @@ private string GetResolvedFilePath(string filePath, ref string newSourceDir)
// and put the deepest directory that file is in as the new
// SourceDir.
//
int pathEndIndex = fullFilePath.LastIndexOf(string.Empty + Path.DirectorySeparatorChar, StringComparison.Ordinal);
int pathEndIndex = fullFilePath.LastIndexOf(Path.DirectorySeparatorChar);

newSourceDir = fullFilePath.Substring(0, pathEndIndex + 1);
newRelativeFilePath = fullFilePath.Substring(pathEndIndex + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ private string GetResolvedFilePath(string filePath, ref string newSourceDir)
// and put the deepest directory that file is in as the new
// SourceDir.
//
int pathEndIndex = fullFilePath.LastIndexOf(string.Empty + Path.DirectorySeparatorChar, StringComparison.Ordinal);
int pathEndIndex = fullFilePath.LastIndexOf(Path.DirectorySeparatorChar);

newSourceDir = fullFilePath.Substring(0, pathEndIndex + 1);
newRelativeFilePath = TaskHelper.GetRootRelativePath(newSourceDir, fullFilePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ private string GetResolvedFilePath(string filePath, ref string newSourceDir)
// and put the deepest directory that file is in as the new
// SourceDir.
//
int pathEndIndex = fullFilePath.LastIndexOf(string.Empty + Path.DirectorySeparatorChar, StringComparison.Ordinal);
int pathEndIndex = fullFilePath.LastIndexOf(Path.DirectorySeparatorChar);

newSourceDir = fullFilePath.Substring(0, pathEndIndex + 1);
newRelativeFilePath = TaskHelper.GetRootRelativePath(newSourceDir, fullFilePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ internal static void AddGesturesFromResourceStrings(string keyGestures, string d
string keyDisplayString;

// break apart first gesture from the rest
int index = keyGestures.IndexOf(MULTIPLEGESTURE_DELIMITER, StringComparison.Ordinal);
int index = keyGestures.IndexOf(MULTIPLEGESTURE_DELIMITER);
if (index >= 0)
{ // multiple gestures exist
keyGestureToken = keyGestures.Substring(0, index);
Expand All @@ -266,7 +266,7 @@ internal static void AddGesturesFromResourceStrings(string keyGestures, string d
}

// similarly, break apart first display string from the rest
index = displayStrings.IndexOf(MULTIPLEGESTURE_DELIMITER, StringComparison.Ordinal);
index = displayStrings.IndexOf(MULTIPLEGESTURE_DELIMITER);
if (index >= 0)
{ // multiple display strings exist
keyDisplayString = displayStrings.Substring(0, index);
Expand Down Expand Up @@ -310,7 +310,7 @@ internal static KeyGesture CreateFromResourceStrings(string keyGestureToken, str
private ModifierKeys _modifiers = ModifierKeys.None;
private Key _key = Key.None;
private string _displayString;
private const string MULTIPLEGESTURE_DELIMITER = ";";
private const char MULTIPLEGESTURE_DELIMITER = ';';
private static TypeConverter _keyGestureConverter = new KeyGestureConverter();
//private static bool _classRegistered = false;
#endregion Private Fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c

if (text != String.Empty)
{
if (text.LastIndexOf(".", StringComparison.Ordinal) == -1)
if (text.LastIndexOf('.') == -1)
{
CursorType ct = (CursorType)Enum.Parse(typeof(CursorType), text);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public BaseActivationFactory(string typeNamespace, string typeFullName)
}
catch (Exception) { }

var lastSegment = moduleName.LastIndexOf(".");
var lastSegment = moduleName.LastIndexOf('.');
if (lastSegment <= 0)
{
Marshal.ThrowExceptionForHR(hr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12498,7 +12498,7 @@ private static TraceList AddToMap(ItemsControl target)
}
if (filename != "none" && s_seqno > 1)
{
int dotIndex = filename.LastIndexOf(".", StringComparison.Ordinal);
int dotIndex = filename.LastIndexOf('.');
if (dotIndex < 0) dotIndex = filename.Length;
filename = filename.Substring(0, dotIndex) +
s_seqno.ToString() +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8238,7 +8238,7 @@ internal void ProcessField()
// is very low. Now we replace image with the included picture uri to get
// the image directly from the specified Uri.
int uriSourceIndex = dnImage.Xaml.IndexOf("UriSource=", StringComparison.Ordinal);
int uriSourceEndIndex = dnImage.Xaml.IndexOf("\"", uriSourceIndex + 11, StringComparison.Ordinal);
int uriSourceEndIndex = dnImage.Xaml.IndexOf('\"', uriSourceIndex + 11);

string imageXaml = dnImage.Xaml.Substring(0, uriSourceIndex);
imageXaml += "UriSource=\"" + pictureUri + "\"";
Expand Down Expand Up @@ -8410,7 +8410,7 @@ private string GetIncludePictureUri(string instructionName)
{
pictureUri = instructionName.Substring(uriIndex, instructionName.Length - uriIndex - 1);

int pictureUriEndIndex = pictureUri.IndexOf("\"", StringComparison.OrdinalIgnoreCase);
int pictureUriEndIndex = pictureUri.IndexOf('\"');
if (pictureUriEndIndex != -1)
{
pictureUri = pictureUri.Substring(0, pictureUriEndIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2231,7 +2231,7 @@ private RtfImageFormat GetImageFormatFromImageSourceName(string imageName)
{
RtfImageFormat imageFormat = RtfImageFormat.Unknown;

int extensionIndex = imageName.LastIndexOf(".", StringComparison.OrdinalIgnoreCase);
int extensionIndex = imageName.LastIndexOf('.');

if (extensionIndex >= 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private void ParseUri( string source, out string typeName, out string localName
localName = ((string)source).Trim();

// split CommandName from its TypeName (e.g. ScrollViewer.PageDownCommand to Scrollviewerand PageDownCommand)
int Offset = localName.LastIndexOf(".", StringComparison.Ordinal);
int Offset = localName.LastIndexOf('.');
if (Offset >= 0)
{
typeName = localName.Substring(0, Offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ internal bool GetTypeInfoId(
string typeFullName,
out short typeId)
{
int dotIndex = typeFullName.LastIndexOf(".", StringComparison.Ordinal);
int dotIndex = typeFullName.LastIndexOf('.');
string typeShortName;
string typeClrNamespace;
if (dotIndex >= 0)
Expand Down
Loading