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

Large collection fixes

This commit is contained in:
Brian Fiete 2023-08-18 12:04:01 -07:00
parent e8880cd59c
commit d0de4776f3
5 changed files with 25 additions and 10 deletions

View file

@ -364,6 +364,7 @@ namespace System.Collections
#unwarn #unwarn
if (sizeof(int_cosize) == 8) if (sizeof(int_cosize) == 8)
return (int_cosize)(hashCode & 0x7FFFFFFF'FFFFFFFFL); return (int_cosize)(hashCode & 0x7FFFFFFF'FFFFFFFFL);
#unwarn
return ((int32)hashCode ^ (int32)((int64)hashCode >> 33)) & 0x7FFFFFFF; return ((int32)hashCode ^ (int32)((int64)hashCode >> 33)) & 0x7FFFFFFF;
} }
@ -629,7 +630,7 @@ namespace System.Collections
return oldPtr; return oldPtr;
} }
private bool RemoveEntry(int32 hashCode, int_cosize index) private bool RemoveEntry(int_cosize hashCode, int_cosize index)
{ {
if (mBuckets != null) if (mBuckets != null)
{ {

View file

@ -1220,7 +1220,7 @@ namespace System.Collections
public struct Enumerator : IEnumerator<T> public struct Enumerator : IEnumerator<T>
{ {
private HashSet<T> mSet; private HashSet<T> mSet;
private int32 mIndex; private int_cosize mIndex;
#if VERSION_HASHSET #if VERSION_HASHSET
private int32 mVersion; private int32 mVersion;
#endif #endif

View file

@ -252,7 +252,7 @@ namespace System.Collections
get get
{ {
return ref mItems[index.Get(mSize)]; return ref mItems[index.Get(mSize)];
} }
[Checked] [Checked]
set set
@ -330,6 +330,7 @@ namespace System.Collections
T* Realloc(int newSize, bool autoFree) T* Realloc(int newSize, bool autoFree)
{ {
Runtime.Assert(newSize <= int_cosize.MaxValue);
T* oldAlloc = null; T* oldAlloc = null;
if (newSize > 0) if (newSize > 0)
{ {

View file

@ -280,6 +280,11 @@ namespace System.IO
class BufferedFileStream : BufferedStream, IFileStream class BufferedFileStream : BufferedStream, IFileStream
{ {
public struct PositionRestorer : this(BufferedFileStream stream, int prevPosition), IDisposable
{
public void Dispose() => stream.Position = prevPosition;
}
protected Platform.BfpFile* mBfpFile; protected Platform.BfpFile* mBfpFile;
protected int64 mBfpFilePos; protected int64 mBfpFilePos;
FileAccess mFileAccess; FileAccess mFileAccess;
@ -329,11 +334,6 @@ namespace System.IO
Delete(); Delete();
} }
protected virtual void Delete()
{
Close();
}
public this(Platform.BfpFile* handle, FileAccess access, int32 bufferSize, bool isAsync) public this(Platform.BfpFile* handle, FileAccess access, int32 bufferSize, bool isAsync)
{ {
mBfpFile = handle; mBfpFile = handle;
@ -440,6 +440,18 @@ namespace System.IO
return .Ok; return .Ok;
} }
public PositionRestorer PushPosition(int position)
{
PositionRestorer restorer = .(this, Position);
Position = position;
return restorer;
}
protected virtual void Delete()
{
Close();
}
public override Result<void> Seek(int64 pos, SeekKind seekKind = .Absolute) public override Result<void> Seek(int64 pos, SeekKind seekKind = .Absolute)
{ {
int64 newPos; int64 newPos;

View file

@ -756,7 +756,7 @@ namespace System
void Realloc(int newSize) void Realloc(int newSize)
{ {
Debug.Assert(AllocSize > 0, "String has been frozen"); Debug.Assert(AllocSize > 0, "String has been frozen");
Debug.Assert((uint)newSize <= cSizeFlags); Runtime.Assert((uint)newSize <= cSizeFlags);
char8* newPtr = new:this char8[newSize]* (?); char8* newPtr = new:this char8[newSize]* (?);
Internal.MemCpy(newPtr, Ptr, mLength); Internal.MemCpy(newPtr, Ptr, mLength);
#if VALGRIND #if VALGRIND
@ -776,8 +776,9 @@ namespace System
void Realloc(char8* newPtr, int newSize) void Realloc(char8* newPtr, int newSize)
{ {
Runtime.Assert(newSize <= int_cosize.MaxValue);
Debug.Assert(AllocSize > 0, "String has been frozen"); Debug.Assert(AllocSize > 0, "String has been frozen");
Debug.Assert((uint)newSize <= cSizeFlags); Runtime.Assert((uint)newSize <= cSizeFlags);
Internal.MemCpy(newPtr, Ptr, mLength); Internal.MemCpy(newPtr, Ptr, mLength);
if (IsDynAlloc) if (IsDynAlloc)
delete:this mPtrOrBuffer; delete:this mPtrOrBuffer;