// File: wichtounet[P]articles/plf_colony_alpha/plf_colony.h
// Function: plf::colony<Trivial<8>, std::allocator<Trivial<8>>, unsigned short>::destroy_all_data()
void destroy_all_data()
	{
	#ifdef PLF_COLONY_TYPE_TRAITS_SUPPORT
		if (total_number_of_elements != 0 && !(std::is_trivially_destructible<element_type>::value))
	#else // If compiler doesn't support traits, iterate regardless - trivial destructors will not be called, hopefully compiler will optimise the 'destruct' loop out for POD types
		if (total_number_of_elements != 0)
	#endif
		{
			total_number_of_elements = 0;

			group_pointer_type previous_group;
			element_pointer_type element_pointer = begin_iterator.element_pointer, end_pointer = first_group->last_endpoint;
			skipfield_pointer_type skipfield_pointer = begin_iterator.skipfield_pointer;

			while (true)
			{
				PLF_COLONY_DESTROY(element_allocator_type, (*this), element_pointer);

				++skipfield_pointer;
				element_pointer += 1 + *skipfield_pointer;
				skipfield_pointer += *skipfield_pointer;

				if (element_pointer == end_pointer) // ie. beyond end of available data
				{
					previous_group = first_group;
					first_group = first_group->next_group;

					PLF_COLONY_DESTROY(group_allocator_type, group_allocator_pair, previous_group);
					PLF_COLONY_DEALLOCATE(group_allocator_type, group_allocator_pair, previous_group, 1);

					if (first_group == NULL)
					{
						return;
					}

					end_pointer = first_group->last_endpoint;
					element_pointer = first_group->elements + *(first_group->skipfield);
					skipfield_pointer = first_group->skipfield + *(first_group->skipfield);
				}
			}
		}
		else // Avoid iteration for both empty groups and trivially-destructible types eg. POD, structs, classes with empty destructors
		{
			// Technically under a type-traits-supporting compiler total_number_of_elements could be non-zero at this point, but since first_group would already be NULL in the case of double-destruction, it's unnecessary to zero total_number_of_elements
			group_pointer_type previous_group;

			while (first_group != NULL)
			{
				previous_group = first_group;
				first_group = first_group->next_group;
				PLF_COLONY_DESTROY(group_allocator_type, group_allocator_pair, previous_group);
				PLF_COLONY_DEALLOCATE(group_allocator_type, group_allocator_pair, previous_group, 1);
			}
		}
	}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq 0x30(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, 0x38(%rax)
je 0x176df
movb $0x1, %al
testb $0x1, %al
jne 0x176df
jmp 0x175a9
movq (%rsp), %rax
movq $0x0, 0x38(%rax)
movq 0x20(%rax), %rcx
movq %rcx, 0x20(%rsp)
movq 0x30(%rax), %rcx
movq (%rcx), %rcx
movq %rcx, 0x18(%rsp)
movq 0x28(%rax), %rax
movq %rax, 0x10(%rsp)
movq (%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x17780
movq 0x10(%rsp), %rax
addq $0x2, %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movzwl (%rax), %ecx
addl $0x1, %ecx
movq 0x20(%rsp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rax
movzwl (%rax), %ecx
movq 0x10(%rsp), %rax
movslq %ecx, %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x20(%rsp), %rax
cmpq 0x18(%rsp), %rax
jne 0x176da
movq (%rsp), %rdi
movq 0x30(%rdi), %rax
movq %rax, 0x28(%rsp)
movq 0x30(%rdi), %rax
movq 0x8(%rax), %rax
movq %rax, 0x30(%rdi)
addq $0x42, %rdi
movq 0x28(%rsp), %rsi
callq 0x177b0
movq (%rsp), %rdi
addq $0x42, %rdi
movq 0x28(%rsp), %rsi
movl $0x1, %edx
callq 0x16ff0
movq (%rsp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x17687
jmp 0x1772e
movq (%rsp), %rcx
movq 0x30(%rcx), %rax
movq (%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x30(%rcx), %rax
movq 0x10(%rax), %rax
movq 0x30(%rcx), %rdx
movq 0x18(%rdx), %rdx
movzwl (%rdx), %edx
movslq %edx, %rdx
shlq $0x3, %rdx
addq %rdx, %rax
movq %rax, 0x20(%rsp)
movq 0x30(%rcx), %rax
movq 0x18(%rax), %rax
movq 0x30(%rcx), %rcx
movq 0x18(%rcx), %rcx
movzwl (%rcx), %ecx
movslq %ecx, %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
jmp 0x175d3
jmp 0x176e1
movq (%rsp), %rax
cmpq $0x0, 0x30(%rax)
je 0x1772c
movq (%rsp), %rdi
movq 0x30(%rdi), %rax
movq %rax, 0x8(%rsp)
movq 0x30(%rdi), %rax
movq 0x8(%rax), %rax
movq %rax, 0x30(%rdi)
addq $0x42, %rdi
movq 0x8(%rsp), %rsi
callq 0x177b0
movq (%rsp), %rdi
addq $0x42, %rdi
movq 0x8(%rsp), %rsi
movl $0x1, %edx
callq 0x16ff0
jmp 0x176e1
jmp 0x1772e
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)