5

Github Optimize DST field access by mahkoh · Pull Request #80200 · rust-lang/rus...

 3 years ago
source link: https://github.com/rust-lang/rust/pull/80200
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Contributor

mahkoh commented 27 days ago

struct X<T: ?Sized>(T)
struct Y<T: ?Sized>(u8, T)

the offset of the unsized field is

0
mem::align_of_val(&self.1)

respectively. This patch changes the expression used to compute these
offsets so that the optimizer can perform this optimization.

Consider

fn f(x: &X<dyn Any>) -> &dyn Any {
    &x.0
}

Before:

test:
	movq	%rsi, %rdx
	movq	16(%rsi), %rax
	leaq	-1(%rax), %rcx
	negq	%rax
	andq	%rcx, %rax
	addq	%rdi, %rax
	retq

After:

test:
	movq	%rsi, %rdx
	movq	%rdi, %rax
	retq

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK