Skip to content

Commit

Permalink
Merge pull request CosmosOS#2657 from Project-Prism/master
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
quajak authored May 3, 2023
2 parents deed775 + ad589b6 commit 1862545
Show file tree
Hide file tree
Showing 51 changed files with 1,483 additions and 1,779 deletions.
16 changes: 10 additions & 6 deletions Tests/Cosmos.TestRunner.TestController/Assert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ public static void AreEqual(int expected, int actual, string message, [CallerFil
if (!xResult)
{
TestController.Debugger.Send("Expected value");
TestController.Debugger.SendNumber((uint) expected);
TestController.Debugger.SendNumber(expected);
TestController.Debugger.Send("Actual value");
TestController.Debugger.SendNumber((uint)actual);
TestController.Debugger.SendNumber(actual);

TestController.Debugger.SendNumber("TestAssertion", "Expected", (uint)expected, 32);
TestController.Debugger.SendNumber("TestAssertion", "Actual", (uint)actual, 32);
TestController.Debugger.Send("Expected value");
TestController.Debugger.SendNumber(expected);
TestController.Debugger.Send("Actual value");
TestController.Debugger.SendNumber(actual);

TestController.Debugger.Send("Numbers sent!");
}
Expand Down Expand Up @@ -130,8 +132,10 @@ public static void AreNotEqual(uint expected, uint actual, string message, [Call
TestController.Debugger.Send("Actual value");
TestController.Debugger.SendNumber((uint)actual);

TestController.Debugger.SendNumber("TestAssertion", "Expected", (uint)expected, 32);
TestController.Debugger.SendNumber("TestAssertion", "Actual", (uint)actual, 32);
TestController.Debugger.Send("Expected value");
TestController.Debugger.SendNumber(expected);
TestController.Debugger.Send("Actual value");
TestController.Debugger.SendNumber(actual);

TestController.Debugger.Send("Numbers sent!");
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Kernels/ConsoleTest/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void TestConsoleEncoding()
Console.WriteLine("Let's write some accented characters: èòàùì");
Console.WriteLine("Let's print all the CP437 codepage");

Sys.Global.mDebugger.SendInternal("");
Sys.Global.Debugger.SendInternal("");

Console.Write("Ç ü é â ä à å ç ê ë è ï î ì Ä Å\n" +
"É æ Æ ô ö ò û ù ÿ Ö Ü ¢ £ ¥ ₧ ƒ\n" +
Expand Down Expand Up @@ -168,4 +168,4 @@ public void TestVariousConsoleFunctions()
Console.SetCursorPosition(cursor.Left, cursor.Top - 1);
}
}
}
}
31 changes: 17 additions & 14 deletions source/Cosmos.Core_Plugs/System/StringImpl.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//#define COSMOSDEBUG
using System;
using System.Globalization;
using System.Text;
using Cosmos.Common;
using IL2CPU.API;
using IL2CPU.API.Attribs;
Expand Down Expand Up @@ -473,7 +474,7 @@ private static int boyerMooreHorsepool(string pattern, string text)

public static int IndexOf(string aThis, string aSubstring, int aIdx, int aLength, StringComparison aComparison)
{
if (aSubstring == String.Empty)
if (aSubstring == string.Empty)
{
return aIdx;
}
Expand Down Expand Up @@ -760,7 +761,7 @@ public static string TrimStart(string aThis, string aSubStr)
throw new ArgumentNullException();
}

internal static unsafe char *GetFirstChar(string aThis, [FieldAccess(Name = "System.Char System.String.m_firstChar")] char* aFirstChar)
internal static unsafe char* GetFirstChar(string aThis, [FieldAccess(Name = "System.Char System.String.m_firstChar")] char* aFirstChar)
{
return aFirstChar;
}
Expand Down Expand Up @@ -880,16 +881,23 @@ private static unsafe int FastCompareStringHelper(uint* strAChars, int countA, u
char* ptr1 = (char*)((byte*)strBChars + diff);
char* ptr2 = (char*)strBChars;
if (*ptr1 != *ptr2)
return (int)*ptr1 - (int)*ptr2;
return (int)*(ptr1 + 1) - (int)*(ptr2 + 1);
{
return *ptr1 - *ptr2;
}

return *(ptr1 + 1) - *(ptr2 + 1);
}
++strBChars;
}

int c;
if (count == -1)
{
if ((c = *(char*)((byte*)strBChars + diff) - *(char*)strBChars) != 0)
{
return c;
}
}
}

return countA - countB;
Expand Down Expand Up @@ -960,17 +968,12 @@ public static int Compare(string strA, int indexA, string strB, int indexB, int
int lengthA = Math.Min(length, strA.Length - indexA);
int lengthB = Math.Min(length, strB.Length - indexB);

switch (comparisonType)
return comparisonType switch
{
case StringComparison.Ordinal:
return CompareOrdinalHelper(strA, indexA, lengthA, strB, indexB, lengthB);

case StringComparison.OrdinalIgnoreCase:
return CompareOrdinalHelperIgnoreCase(strA, indexA, lengthA, strB, indexB, lengthB);

default:
throw new ArgumentException("Not Supported StringComparison");
}
StringComparison.Ordinal => CompareOrdinalHelper(strA, indexA, lengthA, strB, indexB, lengthB),
StringComparison.OrdinalIgnoreCase => CompareOrdinalHelperIgnoreCase(strA, indexA, lengthA, strB, indexB, lengthB),
_ => throw new ArgumentException("String comparison not supported!"),
};
}

public static unsafe int GetNonRandomizedHashCode(string aString)
Expand Down
Loading

0 comments on commit 1862545

Please sign in to comment.