<commit_before>#pragma once


#include "engine/iallocator.h"


namespace Lumix
{


	class LIFOAllocator : public IAllocator
	{
		public:
			LIFOAllocator(IAllocator& source, size_t bucket_size)
				: m_source(source)
				, m_bucket_size(bucket_size)
			{
				m_bucket = source.allocate(bucket_size);
				m_current = m_bucket;
			}


			~LIFOAllocator()
			{
				m_source.deallocate(m_bucket);
			}


			void* allocate(size_t size) override
			{
				uint8* new_address = (uint8*)m_current;
				ASSERT(new_address + size <= (uint8*)m_bucket + m_bucket_size);
				m_current = new_address + size + sizeof(size_t);
				*(size_t*)(new_address + size) = size;
				return new_address;
			}


			void deallocate(void* ptr) override
			{
				if (!ptr) return;
				size_t last_size = *(size_t*)((uint8*)m_current - sizeof(size_t));
				uint8* last_mem = (uint8*)m_current - last_size - sizeof(size_t);
				ASSERT(last_mem == ptr);
				m_current = ptr;
			}


			void* reallocate(void* ptr, size_t size) override
			{
				if (!ptr) return allocate(size);

				size_t last_size = *(size_t*)((uint8*)m_current - sizeof(size_t));
				uint8* last_mem = (uint8*)m_current - last_size - sizeof(size_t);
				ASSERT(last_mem == ptr);
				m_current = last_mem + size + sizeof(size_t);
				*(size_t*)(last_mem + size) = size;
				return ptr;
			}


			void* allocate_aligned(size_t size, size_t align) override
			{
				size_t padding = (align - ((intptr_t)m_current % align)) % align;
				uint8* new_address = (uint8*)m_current + padding;
				ASSERT(new_address + size <= (uint8*)m_bucket + m_bucket_size);
				m_current = new_address + size + sizeof(size_t);
				*(size_t*)(new_address + size) = size + padding;
				ASSERT((intptr_t)new_address % align == 0);
				return new_address;
			}


			void deallocate_aligned(void* ptr) override
			{
				if (!ptr) return;
				size_t last_size_with_padding = *(size_t*)((uint8*)m_current - sizeof(size_t));
				uint8* last_mem = (uint8*)m_current - last_size_with_padding - sizeof(size_t);
				m_current = ptr;
			}


			void* reallocate_aligned(void* ptr, size_t size, size_t align) override
			{
				if (!ptr) return allocate(size);

				size_t last_size_with_padding = *(size_t*)((uint8*)m_current - sizeof(size_t));
				uint8* last_mem = (uint8*)m_current - last_size_with_padding - sizeof(size_t);

				size_t padding = (align - ((intptr_t)last_mem % align)) % align;
				uint8* new_address = (uint8*)last_mem + padding;
				ASSERT(new_address + size <= (uint8*)m_bucket + m_bucket_size);
				m_current = new_address + size + sizeof(size_t);
				*(size_t*)(new_address + size) = size + padding;
				ASSERT((intptr_t)new_address % align == 0);
				return new_address;
			}


		private:
			IAllocator& m_source;
			size_t m_bucket_size;
			void* m_bucket;
			void* m_current;
	};<commit_msg>fixed linux build<commit_after>#pragma once


#include "engine/iallocator.h"


namespace Lumix
{


	class LIFOAllocator : public IAllocator
	{
		public:
			LIFOAllocator(IAllocator& source, size_t bucket_size)
				: m_source(source)
				, m_bucket_size(bucket_size)
			{
				m_bucket = source.allocate(bucket_size);
				m_current = m_bucket;
			}


			~LIFOAllocator()
			{
				m_source.deallocate(m_bucket);
			}


			void* allocate(size_t size) override
			{
				uint8* new_address = (uint8*)m_current;
				ASSERT(new_address + size <= (uint8*)m_bucket + m_bucket_size);
				m_current = new_address + size + sizeof(size_t);
				*(size_t*)(new_address + size) = size;
				return new_address;
			}


			void deallocate(void* ptr) override
			{
				if (!ptr) return;
				size_t last_size = *(size_t*)((uint8*)m_current - sizeof(size_t));
				uint8* last_mem = (uint8*)m_current - last_size - sizeof(size_t);
				ASSERT(last_mem == ptr);
				m_current = ptr;
			}


			void* reallocate(void* ptr, size_t size) override
			{
				if (!ptr) return allocate(size);

				size_t last_size = *(size_t*)((uint8*)m_current - sizeof(size_t));
				uint8* last_mem = (uint8*)m_current - last_size - sizeof(size_t);
				ASSERT(last_mem == ptr);
				m_current = last_mem + size + sizeof(size_t);
				*(size_t*)(last_mem + size) = size;
				return ptr;
			}


			void* allocate_aligned(size_t size, size_t align) override
			{
				size_t padding = (align - ((uintptr)m_current % align)) % align;
				uint8* new_address = (uint8*)m_current + padding;
				ASSERT(new_address + size <= (uint8*)m_bucket + m_bucket_size);
				m_current = new_address + size + sizeof(size_t);
				*(size_t*)(new_address + size) = size + padding;
				ASSERT((uintptr)new_address % align == 0);
				return new_address;
			}


			void deallocate_aligned(void* ptr) override
			{
				if (!ptr) return;
				size_t last_size_with_padding = *(size_t*)((uint8*)m_current - sizeof(size_t));
				uint8* last_mem = (uint8*)m_current - last_size_with_padding - sizeof(size_t);
				m_current = ptr;
			}


			void* reallocate_aligned(void* ptr, size_t size, size_t align) override
			{
				if (!ptr) return allocate(size);

				size_t last_size_with_padding = *(size_t*)((uint8*)m_current - sizeof(size_t));
				uint8* last_mem = (uint8*)m_current - last_size_with_padding - sizeof(size_t);

				size_t padding = (align - ((uintptr)last_mem % align)) % align;
				uint8* new_address = (uint8*)last_mem + padding;
				ASSERT(new_address + size <= (uint8*)m_bucket + m_bucket_size);
				m_current = new_address + size + sizeof(size_t);
				*(size_t*)(new_address + size) = size + padding;
				ASSERT((uintptr)new_address % align == 0);
				return new_address;
			}


		private:
			IAllocator& m_source;
			size_t m_bucket_size;
			void* m_bucket;
			void* m_current;
	};
{'fraction_non_alphanumeric': 0.1317471590909091, 'fraction_numerical': 0.008167613636363636, 'mean_word_length': 3.666942833471417, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5295977', 'n_tokens_mistral': 2472, 'n_tokens_neox': 2056, 'n_words': 404}