diff --git a/BeefLibs/Beefy2D/src/utils/StructuredData.bf b/BeefLibs/Beefy2D/src/utils/StructuredData.bf index 9324acb0..91a39191 100644 --- a/BeefLibs/Beefy2D/src/utils/StructuredData.bf +++ b/BeefLibs/Beefy2D/src/utils/StructuredData.bf @@ -287,7 +287,7 @@ namespace Beefy.utils str.AppendF("Idx:{0}", mIdx); } - public bool TryGet(String name, out Object value) + public bool TryGet(StringView name, out Object value) { var current = GetCurrent(); if ((current == null) || (current.GetType() != typeof(NamedValues))) @@ -316,7 +316,7 @@ namespace Beefy.utils return false; } - public bool TryGet(String name, out NamedValues namedValues, out int keyIdx, out int valueIdx) + public bool TryGet(StringView name, out NamedValues namedValues, out int keyIdx, out int valueIdx) { var current = GetCurrent(); if ((current == null) || (current.GetType() != typeof(NamedValues))) @@ -351,20 +351,20 @@ namespace Beefy.utils return false; } - public bool Contains(String name) + public bool Contains(StringView name) { Object value; return TryGet(name, out value); } - public Object Get(String name) + public Object Get(StringView name) { Object value; TryGet(name, out value); return value; } - public bool Get(String name, ref bool val) + public bool Get(StringView name, ref bool val) { Object aVal = Get(name); if ((aVal == null) || (!(aVal is bool))) @@ -373,7 +373,7 @@ namespace Beefy.utils return true; } - public void Get(String name, ref int32 val) + public void Get(StringView name, ref int32 val) { Object obj = Get(name); if (obj == null) @@ -385,7 +385,7 @@ namespace Beefy.utils } } - public void Get(String name, ref float val) + public void Get(StringView name, ref float val) { Object obj = Get(name); if (obj == null) @@ -398,7 +398,7 @@ namespace Beefy.utils } } - public void Get(String name, ref T val) where T : Enum + public void Get(StringView name, ref T val) where T : Enum { Object obj = Get(name); if (obj == null) @@ -414,7 +414,7 @@ namespace Beefy.utils val = parsedVal; } - public void Get(String name, String outString) + public void Get(StringView name, String outString) { Object obj = Get(name); if (obj == null) @@ -439,7 +439,7 @@ namespace Beefy.utils return mValues[mCurrent.mLastValue]; } - public void GetString(String name, String outString, String theDefault = null) + public void GetString(StringView name, String outString, String theDefault = null) { Object val = Get(name); @@ -650,23 +650,23 @@ namespace Beefy.utils DoAdd(ref mCurrent, new:mBumpAllocator box value); } - public void Add(String value) + public void Add(StringView value) { DoAdd(ref mCurrent, (Object)new:mBumpAllocator String(value)); } - public void Add(String name, T value) where T : struct + public void Add(StringView name, T value) where T : struct { DoAdd(ref mCurrent, AllocStringView(name), new:mBumpAllocator box value); } - public void ConditionalAdd(String name, T value) where T : var + public void ConditionalAdd(StringView name, T value) where T : var { if (value != default(T)) Add(name, value); } - public void ConditionalAdd(String name, T value, T defaultVal) where T : var + public void ConditionalAdd(StringView name, T value, T defaultVal) where T : var { if ((value != null) && (value != defaultVal)) Add(name, value); @@ -718,7 +718,7 @@ namespace Beefy.utils mNextValues.Add(-1); } - StringView AllocStringView(String str) + StringView AllocStringView(StringView str) { int len = str.Length; char8* ptr = (char8*)mBumpAllocator.Alloc(len, 1); @@ -726,20 +726,32 @@ namespace Beefy.utils return StringView(ptr, len); } - public void Add(String name, String value) + public void Add(String name, StringView value) { DoAdd(ref mCurrent, AllocStringView(name), (Object)new:mBumpAllocator String(value)); } - public void ConditionalAdd(String name, String value, String defaultVal) + public void ConditionalAdd(StringView name, StringView value, StringView defaultVal) { - if (value != defaultVal) + if (!(value == defaultVal)) DoAdd(ref mCurrent, AllocStringView(name), (Object)new:mBumpAllocator String(value)); } - public void ConditionalAdd(String name, String value) + public void ConditionalAdd(StringView name, String value, String defaultVal) { - if ((value != null) && (value != "")) + if (!(value == defaultVal)) + DoAdd(ref mCurrent, AllocStringView(name), (Object)new:mBumpAllocator String(value)); + } + + public void ConditionalAdd(StringView name, StringView value) + { + if (!value.IsEmpty) + DoAdd(ref mCurrent, AllocStringView(name), (Object)new:mBumpAllocator String(value)); + } + + public void ConditionalAdd(StringView name, String value) + { + if ((value != null) && (!value.IsEmpty)) DoAdd(ref mCurrent, AllocStringView(name), (Object)new:mBumpAllocator String(value)); } @@ -787,7 +799,7 @@ namespace Beefy.utils } } - public IDisposable Open(String name) + public IDisposable Open(StringView name) { if (mStructuredDisposeProxy == null) { diff --git a/BeefLibs/corlib/src/Collections/Generic/Dictionary.bf b/BeefLibs/corlib/src/Collections/Generic/Dictionary.bf index e34e1039..00604980 100644 --- a/BeefLibs/corlib/src/Collections/Generic/Dictionary.bf +++ b/BeefLibs/corlib/src/Collections/Generic/Dictionary.bf @@ -286,7 +286,7 @@ namespace System.Collections.Generic private void Insert(TKey key, TValue value, bool add) { if (mBuckets == null) Initialize(0); - int_cosize hashCode = (int_cosize)key.GetHashCode() & 0x7FFFFFFF; + int32 hashCode = (int32)key.GetHashCode() & 0x7FFFFFFF; int_cosize targetBucket = hashCode % (int_cosize)mBuckets.Count; for (int_cosize i = mBuckets[targetBucket]; i >= 0; i = mEntries[i].mNext) @@ -335,7 +335,7 @@ namespace System.Collections.Generic private bool Insert(TKey key, bool add, out TKey* keyPtr, out TValue* valuePtr) { if (mBuckets == null) Initialize(0); - int_cosize hashCode = (int_cosize)key.GetHashCode() & 0x7FFFFFFF; + int32 hashCode = (int32)key.GetHashCode() & 0x7FFFFFFF; int_cosize targetBucket = hashCode % (int_cosize)mBuckets.Count; for (int_cosize i = mBuckets[targetBucket]; i >= 0; i = mEntries[i].mNext) @@ -413,7 +413,7 @@ namespace System.Collections.Generic { if (newEntries[i].mHashCode != -1) { - newEntries[i].mHashCode = (int_cosize)newEntries[i].mKey.GetHashCode() & 0x7FFFFFFF; + newEntries[i].mHashCode = (int32)newEntries[i].mKey.GetHashCode() & 0x7FFFFFFF; } } } @@ -445,7 +445,7 @@ namespace System.Collections.Generic if (mBuckets != null) { - int_cosize hashCode = (int_cosize)key.GetHashCode() & 0x7FFFFFFF; + int32 hashCode = (int32)key.GetHashCode() & 0x7FFFFFFF; int_cosize bucket = hashCode % (int_cosize)mBuckets.Count; int_cosize last = -1; for (int_cosize i = mBuckets[bucket]; i >= 0; last = i,i = mEntries[i].mNext) diff --git a/BeefLibs/corlib/src/Collections/Generic/HashSet.bf b/BeefLibs/corlib/src/Collections/Generic/HashSet.bf index 1df32232..fcf9047a 100644 --- a/BeefLibs/corlib/src/Collections/Generic/HashSet.bf +++ b/BeefLibs/corlib/src/Collections/Generic/HashSet.bf @@ -196,6 +196,24 @@ namespace System.Collections.Generic return false; } + public bool ContainsWith(TAltKey item) where TAltKey : IOpEquals, IHashable + { + if (mBuckets != null) + { + int32 hashCode = (int32)item.GetHashCode() & Lower31BitMask; + // see note at "HashSet" level describing why "- 1" appears in for loop + for (int32 i = mBuckets[hashCode % mBuckets.Count] - 1; i >= 0; i = mSlots[i].mNext) + { + if (mSlots[i].mHashCode == hashCode && /*m_comparer.Equals*/(mSlots[i].mValue == item)) + { + return true; + } + } + } + // either m_buckets is null or wasn't found + return false; + } + /// Copy items in this hashset to array, starting at arrayIndex /// @param array array to add items to /// @param arrayIndex index to start at diff --git a/BeefLibs/corlib/src/System.bf b/BeefLibs/corlib/src/System.bf index f56ebe20..8ccead36 100644 --- a/BeefLibs/corlib/src/System.bf +++ b/BeefLibs/corlib/src/System.bf @@ -4,7 +4,11 @@ using System.Collections.Generic; namespace System { // Collection size type +#if BF_LARGE_COLLECTIONS + typealias int_cosize = int64; +#else typealias int_cosize = int32; +#endif [AlwaysInclude] static class CompilerSettings @@ -17,6 +21,18 @@ namespace System public const bool cHasVDataExtender = true; public const int32 cVDataIntefaceSlotCount = 16; +#if BF_LARGE_STRINGS + public const bool cHasLargeStrings = true; +#else + public const bool cHasLargeStrings = false; +#endif + +#if BF_LARGE_COLLECTIONS + public const bool cHasLargeCollections = true; +#else + public const bool cHasLargeCollections = false; +#endif + static this() { // This ensures this gets included in vdata diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index 546a6689..8f917b00 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -16492,8 +16492,8 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod if (checkType == NULL) break; - bool foundExactMatch = false; - BfOperatorDef* oppositeOperatorDef = NULL; + bool foundExactMatch = false; + Array oppositeOperatorDefs; for (auto operatorDef : checkType->mTypeDef->mOperators) { @@ -16502,7 +16502,7 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod allowOp = true; if (allowOp) - { + { foundOp = true; if (methodMatcher.CheckMethod(checkType, operatorDef, false)) { @@ -16512,14 +16512,17 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod } } else if (operatorDef->mOperatorDeclaration->mBinOp == oppositeBinaryOp) - oppositeOperatorDef = operatorDef; + oppositeOperatorDefs.Add(operatorDef); } - if (((methodMatcher.mBestMethodDef == NULL) || (!foundExactMatch)) && (oppositeOperatorDef != NULL)) + if (((methodMatcher.mBestMethodDef == NULL) || (!foundExactMatch)) && (!oppositeOperatorDefs.IsEmpty())) { foundOp = true; - if (methodMatcher.CheckMethod(checkType, oppositeOperatorDef, false)) - methodMatcher.mSelfType = entry.mSrcType; + for (auto oppositeOperatorDef : oppositeOperatorDefs) + { + if (methodMatcher.CheckMethod(checkType, oppositeOperatorDef, false)) + methodMatcher.mSelfType = entry.mSrcType; + } } } if (methodMatcher.mBestMethodDef != NULL) diff --git a/IDEHelper/DbgExprEvaluator.cpp b/IDEHelper/DbgExprEvaluator.cpp index 2ca03451..9305bfc9 100644 --- a/IDEHelper/DbgExprEvaluator.cpp +++ b/IDEHelper/DbgExprEvaluator.cpp @@ -1153,10 +1153,29 @@ DbgTypedValue DbgExprEvaluator::GetBeefTypeById(int typeId) void DbgExprEvaluator::BeefStringToString(addr_target addr, String& outStr) { + mDebugTarget->GetCompilerSettings(); int objectSize = mDebugTarget->mBfObjectSize; - int32 strLen = mDebugger->ReadMemory(addr + objectSize); - addr_target charPtr = mDebugger->ReadMemory(addr + objectSize + 4 + 4); + int32 strLen = 0; + addr_target charPtr = 0; + if (!mDebugTarget->mBfHasLargeStrings) + { + strLen = mDebugger->ReadMemory(addr + objectSize); + int32 allocSizeAndFlags = mDebugger->ReadMemory(addr + objectSize + 4); + if ((allocSizeAndFlags & 0x40000000) != 0) + charPtr = mDebugger->ReadMemory(addr + objectSize + 4 + 4); + else + charPtr = addr + objectSize + 4 + 4; + } + else + { + strLen = mDebugger->ReadMemory(addr + objectSize); + int64 allocSizeAndFlags = mDebugger->ReadMemory(addr + objectSize + 8); + if ((allocSizeAndFlags & 0x40000000'00000000LL) != 0) + charPtr = mDebugger->ReadMemory(addr + objectSize + 8 + 8); + else + charPtr = addr + objectSize + 4 + 4; + } if ((strLen > 0) && (strLen < 4096)) { diff --git a/IDEHelper/DebugTarget.cpp b/IDEHelper/DebugTarget.cpp index 80c90e1e..e6f751da 100644 --- a/IDEHelper/DebugTarget.cpp +++ b/IDEHelper/DebugTarget.cpp @@ -20,6 +20,8 @@ DebugTarget::DebugTarget(WinDebugger* debugger) mCheckedCompilerSettings = false; mBfObjectHasFlags = false; mBfObjectHasVDataExtender = false; + mBfHasLargeStrings = false; + mBfHasLargeCollections = false; mBfObjectVDataIntefaceSlotCount = -1; mBfObjectSize = -1; mDebugger = debugger; @@ -887,6 +889,10 @@ void DebugTarget::GetCompilerSettings() mBfObjectHasFlags = member->mConstValue != 0; if (strcmp(member->mName, "cHasVDataExtender") == 0) mBfObjectHasVDataExtender = member->mConstValue != 0; + if (strcmp(member->mName, "cHasLargeStrings") == 0) + mBfHasLargeStrings = member->mConstValue != 0; + if (strcmp(member->mName, "cHasLargeCollections") == 0) + mBfHasLargeCollections = member->mConstValue != 0; if (strcmp(member->mName, "cVDataIntefaceSlotCount") == 0) mBfObjectVDataIntefaceSlotCount = (int)member->mConstValue; } diff --git a/IDEHelper/DebugTarget.h b/IDEHelper/DebugTarget.h index 7e4263fb..65d68058 100644 --- a/IDEHelper/DebugTarget.h +++ b/IDEHelper/DebugTarget.h @@ -49,6 +49,8 @@ public: bool mCheckedCompilerSettings; bool mBfObjectHasFlags; bool mBfObjectHasVDataExtender; + bool mBfHasLargeStrings; + bool mBfHasLargeCollections; int mBfObjectVDataIntefaceSlotCount; int mBfObjectSize;