1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-16 15:24:10 +02:00

Improvements to overflow arithmetic

This commit is contained in:
Brian Fiete 2022-01-11 10:36:22 -05:00
parent eb375362a1
commit bf97431cdb
12 changed files with 91 additions and 45 deletions

View file

@ -397,14 +397,14 @@ namespace System
let intSize = sizeof(int);
while (charsLeft >= intSize)
{
hash = (hash ^ *((int*)curPtr)) + (hash * 16777619);
hash = (hash ^ *((int*)curPtr)) &+ (hash &* 16777619);
charsLeft -= intSize;
curPtr += intSize;
}
while (charsLeft > 1)
{
hash = ((hash ^ (int)*curPtr) << 5) - hash;
hash = ((hash ^ (int)*curPtr) << 5) &- hash;
charsLeft--;
curPtr++;
}
@ -1774,8 +1774,8 @@ namespace System
//Contract.Assert((char8A | char8B) <= 0x7F, "strings have to be ASCII");
// uppercase both chars - notice that we need just one compare per char
if ((uint32)(charA - 'a') <= (uint32)('z' - 'a')) charA -= 0x20;
if ((uint32)(charB - 'a') <= (uint32)('z' - 'a')) charB -= 0x20;
if ((uint32)(charA &- 'a') <= (uint32)('z' - 'a')) charA -= 0x20;
if ((uint32)(charB &- 'a') <= (uint32)('z' - 'a')) charB -= 0x20;
//Return the (case-insensitive) difference between them.
if (charA != charB)
@ -1807,8 +1807,8 @@ namespace System
//Contract.Assert((char8A | char8B) <= 0x7F, "strings have to be ASCII");
// uppercase both chars - notice that we need just one compare per char
if ((uint32)(charA - 'a') <= (uint32)('z' - 'a')) charA -= 0x20;
if ((uint32)(charB - 'a') <= (uint32)('z' - 'a')) charB -= 0x20;
if ((uint32)(charA &- 'a') <= (uint32)('z' - 'a')) charA -= 0x20;
if ((uint32)(charB &- 'a') <= (uint32)('z' - 'a')) charB -= 0x20;
//Return the (case-insensitive) difference between them.
if (charA != charB)
@ -1835,8 +1835,8 @@ namespace System
//Contract.Assert((char8A | char8B) <= 0x7F, "strings have to be ASCII");
// uppercase both chars - notice that we need just one compare per char
if ((uint32)(charA - 'a') <= (uint32)('z' - 'a')) charA -= 0x20;
if ((uint32)(charB - 'a') <= (uint32)('z' - 'a')) charB -= 0x20;
if ((uint32)(charA &- 'a') <= (uint32)('z' - 'a')) charA -= 0x20;
if ((uint32)(charB &- 'a') <= (uint32)('z' - 'a')) charB -= 0x20;
//Return the (case-insensitive) difference between them.
if (charA != charB)