From f65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Tue, 29 Oct 2024 14:49:26 +0800 Subject: format * format * Minor test fixes * enable checking cpp format in ci --- source/core/slang-allocator.h | 112 +++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 62 deletions(-) (limited to 'source/core/slang-allocator.h') diff --git a/source/core/slang-allocator.h b/source/core/slang-allocator.h index 8942f993b..03cfabe40 100644 --- a/source/core/slang-allocator.h +++ b/source/core/slang-allocator.h @@ -5,89 +5,77 @@ #include #ifdef _MSC_VER -# include +#include #endif #include namespace Slang { - inline void* alignedAllocate(size_t size, size_t alignment) - { +inline void* alignedAllocate(size_t size, size_t alignment) +{ #ifdef _MSC_VER - return _aligned_malloc(size, alignment); + return _aligned_malloc(size, alignment); #elif defined(__CYGWIN__) - return aligned_alloc(alignment, size); + return aligned_alloc(alignment, size); #else - void* rs = nullptr; - int succ = posix_memalign(&rs, alignment, size); - return (succ == 0) ? rs : nullptr; + void* rs = nullptr; + int succ = posix_memalign(&rs, alignment, size); + return (succ == 0) ? rs : nullptr; #endif - } +} - inline void alignedDeallocate(void* ptr) - { +inline void alignedDeallocate(void* ptr) +{ #ifdef _MSC_VER - _aligned_free(ptr); + _aligned_free(ptr); #else - free(ptr); + free(ptr); #endif - } +} - class StandardAllocator - { - public: - // not really called - void* allocate(size_t size) - { - return ::malloc(size); - } - void deallocate(void * ptr) - { - return ::free(ptr); - } - }; +class StandardAllocator +{ +public: + // not really called + void* allocate(size_t size) { return ::malloc(size); } + void deallocate(void* ptr) { return ::free(ptr); } +}; - template - class AlignedAllocator - { - public: - void* allocate(size_t size) - { - return alignedAllocate(size, ALIGNMENT); - } - void deallocate(void * ptr) - { - return alignedDeallocate(ptr); - } - }; +template +class AlignedAllocator +{ +public: + void* allocate(size_t size) { return alignedAllocate(size, ALIGNMENT); } + void deallocate(void* ptr) { return alignedDeallocate(ptr); } +}; - template - class AllocateMethod +template +class AllocateMethod +{ +public: + static inline T* allocateArray(Index count) { - public: - static inline T* allocateArray(Index count) + TAllocator allocator; + T* rs = (T*)allocator.allocate(count * sizeof(T)); + if (!std::is_trivially_constructible::value) { - TAllocator allocator; - T* rs = (T*)allocator.allocate(count * sizeof(T)); - if (!std::is_trivially_constructible::value) - { - for (Index i = 0; i < count; i++) - new (rs + i) T(); - } - return rs; + for (Index i = 0; i < count; i++) + new (rs + i) T(); } - static inline void deallocateArray(T* ptr, Index count) + return rs; + } + static inline void deallocateArray(T* ptr, Index count) + { + TAllocator allocator; + if (!std::is_trivially_destructible::value) { - TAllocator allocator; - if (!std::is_trivially_destructible::value) - { - for (Index i = 0; i < count; i++) - ptr[i].~T(); - } - allocator.deallocate(ptr); + for (Index i = 0; i < count; i++) + ptr[i].~T(); } - }; + allocator.deallocate(ptr); + } +}; #if 0 template @@ -104,6 +92,6 @@ namespace Slang } }; #endif -} +} // namespace Slang #endif -- cgit v1.2.3