Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add GenericArray::remove, remove_unchecked #147

Closed
wants to merge 2 commits into from

Conversation

Easyoakland
Copy link

Add new methods for removing an element from an arbitrary index. I'm surprised this wasn't already implemented, so maybe I missed it.

Here's what the assembly looks like for GenericArray::<u8,4>.remove_unchecked

Ignoring the removed element:

	sub rsp, 40
	mov r8, rdx

	mov dword ptr [rsp + 36], ecx

	lea rcx, [rsp + rdx]

	add rcx, 36

	add rdx, rsp

	add rdx, 37

	xor r8, 3

	call memmove

	mov eax, dword ptr [rsp + 36]

	add rsp, 40
	ret

Ignoring the remaining array:

	push rax

	mov dword ptr [rsp + 4], ecx

	movzx eax, byte ptr [rsp + rdx + 4]

	pop rcx

	ret

Using both the remaining array and element:

	push rsi
	sub rsp, 48
	mov r8, rdx

	mov dword ptr [rsp + 44], ecx

	lea rcx, [rsp + rdx]

	add rcx, 44

	add rdx, rsp

	add rdx, 45

	movzx esi, byte ptr [rsp + r8 + 44]

	xor r8, 3

	call memmove

	shl esi, 24
	mov eax, 16777215
	and eax, dword ptr [rsp + 44]
	or eax, esi

	add rsp, 48
	pop rsi
	ret

@Easyoakland
Copy link
Author

Also, the added tests pass miri so I'm relatively confident the implementation is correct.

novacrazy added a commit that referenced this pull request Jul 5, 2024
@novacrazy
Copy link
Collaborator

I've implemented this for 1.1.0 along with a swap_remove in a new Remove trait built on GenericSequence. Codegen in my version is essentially identical.

@novacrazy novacrazy closed this Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants