Skip to content

Minor changes in std::mem #13643

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

Merged
merged 1 commit into from
Apr 20, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/libstd/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ pub fn size_of_val<T>(_val: &T) -> uint {
/// Useful for building structures containing variable-length arrays.
#[inline]
pub fn nonzero_size_of<T>() -> uint {
let s = size_of::<T>();
if s == 0 { 1 } else { s }
match size_of::<T>() {
0 => 1,
x => x
}
}

/// Returns the size in bytes of the type of the value that `_val` points to.
Expand Down Expand Up @@ -222,7 +224,6 @@ pub unsafe fn move_val_init<T>(dst: &mut T, src: T) {
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
#[cfg(target_endian = "big")] #[inline] pub fn from_be64(x: u64) -> u64 { x }


/**
* Swap the values at two mutable locations of the same type, without
* deinitialising or copying either one.
Expand All @@ -238,7 +239,7 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
ptr::copy_nonoverlapping_memory(x, &*y, 1);
ptr::copy_nonoverlapping_memory(y, &t, 1);

// y and t now point to the same thing, but we need to completely forget `tmp`
// y and t now point to the same thing, but we need to completely forget `t`
// because it's no longer relevant.
cast::forget(t);
}
Expand Down Expand Up @@ -359,6 +360,7 @@ mod tests {
}
}

// FIXME #13642 (these benchmarks should be in another place)
/// Completely miscellaneous language-construct benchmarks.
#[cfg(test)]
mod bench {
Expand Down