From 3c505c22673701339d35eb2151f01c16eb3c78c3 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 14 Sep 2018 14:16:28 -0400 Subject: Improvements around IR representation and memory usage (#635) * * Remove dispose from IRInst * Use MemoryArena instead of MemoryPool * Make all IRInst not require Dtor - by having ref counted array store ptrs that need freeing * Increase block size - typically compilation is 2Mb of IR space(!) * Fix issues around StringRepresentation::equal because null has special meaning. * Don't bother to construct as String to compare StringRepresentation, just used UnownedStringSlice. * Added fromLiteral support to UnownedStringSlice and use instead of strlen version. * Use more conventional way to test StringRepresentation against a String. * Fix gcc/clang template problem with cast. --- source/core/smart-pointer.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'source/core/smart-pointer.h') diff --git a/source/core/smart-pointer.h b/source/core/smart-pointer.h index f45618050..abd7763ee 100644 --- a/source/core/smart-pointer.h +++ b/source/core/smart-pointer.h @@ -61,6 +61,18 @@ namespace Slang { return referenceCount; } + + // Use instead of dynamic_cast as it allows for replacement without using Rtti in the future + template + SLANG_FORCE_INLINE const T* dynamicCast() const + { + return dynamic_cast(this); + } + template + SLANG_FORCE_INLINE T* dynamicCast() + { + return dynamic_cast(this); + } }; inline void addReference(RefObject* obj) @@ -78,7 +90,7 @@ namespace Slang struct RefPtr { RefPtr() - : pointer(0) + : pointer(nullptr) {} RefPtr(T* p) @@ -96,7 +108,7 @@ namespace Slang RefPtr(RefPtr&& p) : pointer(p.pointer) { - p.pointer = 0; + p.pointer = nullptr; } template @@ -170,8 +182,7 @@ namespace Slang template RefPtr As() const { - RefPtr result(dynamic_cast(pointer)); - return result; + return RefPtr(pointer->template dynamicCast()); } ~RefPtr() -- cgit v1.2.3