1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-07-04 15:26:00 +02:00

Optimizations, switching CanImplicitlyCast method, new CPU rate checker

This commit is contained in:
Brian Fiete 2019-11-19 09:58:35 -08:00
parent 39fd8d2624
commit 098ad1ce55
25 changed files with 759 additions and 301 deletions

View file

@ -639,7 +639,7 @@ public:
this->mSize++;
}
void Insert(intptr idx, T* vals, intptr size)
void Insert(intptr idx, const T* vals, intptr size)
{
BF_ASSERT((uintptr)idx <= (uintptr)this->mSize);
if (this->mSize + size > this->mAllocSize)
@ -934,7 +934,7 @@ public:
this->mSize++;
}
void Insert(intptr idx, T* vals, intptr size)
void Insert(intptr idx, const T* vals, intptr size)
{
BF_ASSERT((uintptr)idx <= (uintptr)this->mSize);
if (this->mSize + size > this->mAllocSize)

View file

@ -355,7 +355,7 @@ static int64 GetTimestamp()
#ifdef BF_PLATFORM_WINDOWS
return __rdtsc() / 100;
#else
return BfpSystem_GetCPUTick();
return BfpSystem_GetCPUTick() / 100;
#endif
}

View file

@ -186,7 +186,7 @@ public:
return mPrevSizes + (int)((uint8*)ptr - mCurAlloc);
}
uint8* AllocBytes(int wantSize, int alignSize, const char* dbgName = "AllocBytes")
uint8* AllocBytes(intptr wantSize, int alignSize, const char* dbgName = "AllocBytes")
{
mCurPtr = (uint8*)(((intptr)mCurPtr + alignSize - 1) & ~(alignSize - 1));
@ -194,7 +194,7 @@ public:
return retVal;
}
uint8* AllocBytes(int wantSize, const char* dbgName = "AllocBytes")
uint8* AllocBytes(intptr wantSize, const char* dbgName = "AllocBytes")
{
#ifdef BUMPALLOC_TRACKALLOCS
BumpAllocTrackedEntry* allocSizePtr;
@ -237,6 +237,11 @@ class AllocatorBump
public:
BumpAllocator* mAlloc;
AllocatorBump()
{
mAlloc = NULL;
}
T* allocate(intptr count)
{
return (T*)mAlloc->AllocBytes((int)(sizeof(T) * count), alignof(T));
@ -245,6 +250,16 @@ public:
void deallocate(T* ptr)
{
}
void* rawAllocate(intptr size)
{
return mAlloc->AllocBytes(size, 16);
}
void rawDeallocate(void* ptr)
{
}
};

View file

@ -107,6 +107,42 @@ void ChunkedDataBuffer::Write(uint8 byte)
mSize++;
}
void ChunkedDataBuffer::Write_2(uint16 val)
{
while (mWriteCurPtr + 2 > mWriteCurAlloc + ALLOC_SIZE)
{
Write((uint8*)&val, 2);
return;
}
*(uint16*)mWriteCurPtr = val;
mWriteCurPtr += 2;
mSize += 2;
}
void ChunkedDataBuffer::Write_3(uint32 val)
{
while (mWriteCurPtr + 3 > mWriteCurAlloc + ALLOC_SIZE)
{
Write((uint8*)&val, 3);
return;
}
*(uint32*)mWriteCurPtr = val;
mWriteCurPtr += 3;
mSize += 3;
}
void ChunkedDataBuffer::Write_4(uint32 val)
{
while (mWriteCurPtr + 4 > mWriteCurAlloc + ALLOC_SIZE)
{
Write((uint8*)&val, 4);
return;
}
*(uint32*)mWriteCurPtr = val;
mWriteCurPtr += 4;
mSize += 4;
}
int ChunkedDataBuffer::GetReadPos()
{
return mReadPoolIdx * ALLOC_SIZE + (int)(mReadCurPtr - mReadCurAlloc);

View file

@ -32,6 +32,9 @@ public:
void GrowPool();
void Write(const void* data, int size);
void Write(uint8 byte);
void Write_2(uint16 val);
void Write_3(uint32 val);
void Write_4(uint32 val);
int GetReadPos();
void SetReadPos(int pos);
void NextReadPool();

View file

@ -1,12 +1,12 @@
#pragma once
#include "../Common.h"
#include "Array.h"
#include <unordered_map>
NS_BF_BEGIN;
template <typename TKey>
class HashSet
template <typename TKey, typename TAlloc = AllocatorCLib<TKey> >
class HashSet : public TAlloc
{
public:
typedef int int_cosize;
@ -254,14 +254,14 @@ private:
Resize(ExpandSize(mCount), false);
}
void Resize(int newSize, bool forceNewHashCodes)
void Resize(intptr newSize, bool forceNewHashCodes)
{
BF_ASSERT(newSize >= mAllocSize);
int_cosize* newBuckets = new int_cosize[newSize];
int_cosize* newBuckets = (int_cosize*)rawAllocate(sizeof(int_cosize) * newSize);
for (int_cosize i = 0; i < newSize; i++)
newBuckets[i] = -1;
Entry* newEntries = new Entry[newSize];
//mEntries.CopyTo(newEntries, 0, 0, mCount);
Entry* newEntries = (Entry*)rawAllocate(sizeof(Entry)*newSize);
for (int i = 0; i < mCount; i++)
{
auto& newEntry = newEntries[i];
@ -294,12 +294,12 @@ private:
}
}
delete[] mBuckets;
delete[] mEntries;
rawDeallocate(mBuckets);
rawDeallocate(mEntries);
mBuckets = newBuckets;
mEntries = newEntries;
mAllocSize = newSize;
mAllocSize = (int_cosize)newSize;
}
int FindEntry(const TKey& key)
@ -332,10 +332,10 @@ private:
void Initialize(intptr capacity)
{
int_cosize size = GetPrimeish((int_cosize)capacity);
mBuckets = new int_cosize[size];
mBuckets = (int_cosize*)rawAllocate(sizeof(int_cosize) * size);
mAllocSize = size;
for (int_cosize i = 0; i < (int_cosize)mAllocSize; i++) mBuckets[i] = -1;
mEntries = new Entry[size];
mEntries = (Entry*)rawAllocate(sizeof(Entry) * size);
mFreeList = -1;
}
@ -431,8 +431,8 @@ public:
}
else
{
mBuckets = new int_cosize[mAllocSize];
mEntries = new Entry[mAllocSize];
mBuckets = (int_cosize*)rawAllocate(sizeof(int_cosize) * mAllocSize);
mEntries = (Entry*)rawAllocate(sizeof(Entry) * mAllocSize);
for (int_cosize i = 0; i < mAllocSize; i++)
mBuckets[i] = val.mBuckets[i];
@ -476,8 +476,8 @@ public:
}
}
delete[] mBuckets;
delete[] mEntries;
rawDeallocate(mBuckets);
rawDeallocate(mEntries);
}
HashSet& operator=(const HashSet& rhs)

View file

@ -217,7 +217,7 @@ public:
BF_ASSERT((uintptr)idx < (uintptr)this->mSize);
return this->mVals[idx];
}
bool operator==(const SizedArrayBase& arrB) const
{
if (this->mSize != arrB.mSize)
@ -288,6 +288,11 @@ public:
this->mSize = 0;
}
void Clear()
{
this->mSize = 0;
}
/*void Free()
{
if (this->mVals != NULL)
@ -1060,17 +1065,27 @@ public:
}
};
template <typename T>
static bool operator==(const ArrayBase<T>& arrA, const SizedArrayBase<T>& arrB)
{
if (arrA.mSize != arrB.mSize)
return false;
for (intptr i = 0; i < arrA.mSize; i++)
if (arrA.mVals[i] != arrB.mVals[i])
return false;
return true;
}
NS_BF_END;
/*namespace std
namespace std
{
template<typename T>
struct hash<Beefy::Array<T> >
struct hash<Beefy::SizedArrayImpl<T> >
{
size_t operator()(const Beefy::Array<T>& val) const
size_t operator()(const Beefy::SizedArrayImpl<T>& val) const
{
return _Hash_seq((const uint8*)val.mVals, sizeof(T) * val.mSize);
return HashBytes((const uint8*)val.mVals, sizeof(T) * val.mSize);
}
};
}*/
}