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

Use raw pointer casts for slice, str's .as_ptr() #31999

Merged
merged 1 commit into from
Mar 2, 2016

Conversation

bluss
Copy link
Member

@bluss bluss commented Mar 1, 2016

Use raw pointer casts for slice, str's .as_ptr()

We can now use raw pointer casts *const [T] as *const T and
*const str as *const u8 instead of .repr() for getting the
pointer out of a slice.

We can now use raw pointer casts `*const [T] as *const T` and
`*const str as *const u8` instead of .repr() for getting the
pointer out of a slice.
@rust-highfive
Copy link
Collaborator

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@bluss
Copy link
Member Author

bluss commented Mar 1, 2016

This should be a good idea, using simpler code should improve compile time (however slightly). We don't have to call .repr() in this method anymore, repr uses transmute_copy, read, uninitialized, copy_nonoverlapping in turn.

It looks like it generates exactly the same code in the end. https://gist.github.com/bluss/085ae73a253b9cc82788

ndarray's benchmarks stay the same, so it didn't seem to affect any slice loop optimizations that I could see.

@eddyb
Copy link
Member

eddyb commented Mar 1, 2016

This is great IMO! @bors r+

@bors
Copy link
Contributor

bors commented Mar 1, 2016

📌 Commit 63c4065 has been approved by eddyb

Manishearth added a commit to Manishearth/rust that referenced this pull request Mar 2, 2016
Use raw pointer casts for slice, str's .as_ptr()

We can now use raw pointer casts `*const [T] as *const T` and
`*const str as *const u8` instead of .repr() for getting the
pointer out of a slice.
bors added a commit that referenced this pull request Mar 2, 2016
@bors bors merged commit 63c4065 into rust-lang:master Mar 2, 2016
@bluss bluss deleted the fundamental-raw-ptr branch March 2, 2016 04:57
@SimonSapin
Copy link
Contributor

I understand from context (and by assuming this code is correct) what as does here, but it seems a bit magical. Could someone replace “TODO: explain unsized situation” at https://doc.rust-lang.org/nomicon/casts.html with an explanation?

@bluss
Copy link
Member Author

bluss commented Mar 8, 2016

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.

6 participants