// File: /workspace/github_cpp_makefile_star2_O3/wichtounet[P]articles/plf_colony_alpha/plf_colony.h
// Function: plf::colony<NonTrivialStringMovable, std::allocator<NonTrivialStringMovable>, 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:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
cmpq $0x0, 0x38(%rdi)
movq %rdi, %rbx
je 0x1a8e6
movq $0x0, 0x38(%rbx)
movq 0x20(%rbx), %r14
movq 0x28(%rbx), %r15
movq 0x30(%rbx), %rax
movq (%rax), %r12
movq (%r14), %rdi
leaq 0x10(%r14), %rax
cmpq %rax, %rdi
je 0x1a876
callq 0x41a0
movzwl 0x2(%r15), %eax
leaq (%rax,%rax,4), %rcx
leaq 0x2(%r15,%rax,2), %r15
leaq 0x28(%r14,%rcx,8), %r14
cmpq %r12, %r14
jne 0x1a865
movq 0x30(%rbx), %r14
movq 0x8(%r14), %rax
movq %rax, 0x30(%rbx)
movq 0x10(%r14), %rdi
callq 0x41a0
movq %r14, %rdi
callq 0x41a0
movq 0x30(%rbx), %rax
testq %rax, %rax
je 0x1a8ef
movq 0x18(%rax), %rcx
movzwl (%rcx), %edx
leaq (%rdx,%rdx,4), %r14
leaq (%rcx,%rdx,2), %r15
shll $0x3, %r14d
addq 0x10(%rax), %r14
jmp 0x1a862
movq 0x8(%r14), %rax
movq %rax, 0x30(%rbx)
movq 0x10(%r14), %rdi
callq 0x41a0
movq %r14, %rdi
callq 0x41a0
movq 0x30(%rbx), %r14
testq %r14, %r14
jne 0x1a8cd
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop