Skip to content

Commit 895ee9b

Browse files
committed
---
yaml --- r: 58323 b: refs/heads/auto c: 7d22437 h: refs/heads/master i: 58321: e1801cb 58319: d81768e v: v3
1 parent 2606fe8 commit 895ee9b

File tree

7 files changed

+71
-13
lines changed

7 files changed

+71
-13
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: c49cf8b3300a97201058debd63b0f7aef34d3c35
17+
refs/heads/auto: 7d22437ecdc5b52f8517ffde6207347739b26553
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

branches/auto/src/libcore/core.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ pub mod rand;
228228
pub mod run;
229229
pub mod sys;
230230
pub mod cast;
231+
pub mod flate;
231232
pub mod repr;
232233
pub mod cleanup;
233234
pub mod reflect;

branches/auto/src/libstd/flate.rs renamed to branches/auto/src/libcore/flate.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ Simple compression
1515
*/
1616

1717
use libc;
18-
use core::libc::{c_void, size_t, c_int};
18+
use libc::{c_void, size_t, c_int};
1919
use vec;
2020

21-
#[cfg(test)] use core::rand;
22-
#[cfg(test)] use core::rand::RngUtil;
21+
#[cfg(test)] use rand;
22+
#[cfg(test)] use rand::RngUtil;
2323

2424
pub mod rustrt {
25-
use core::libc::{c_int, c_void, size_t};
25+
use libc::{c_int, c_void, size_t};
2626

2727
#[link_name = "rustrt"]
2828
pub extern {

branches/auto/src/libcore/util.rs

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Miscellaneous helpers for common patterns.
1515
*/
1616

1717
use prelude::*;
18+
use unstable::intrinsics;
1819

1920
/// The identity function.
2021
#[inline(always)]
@@ -49,18 +50,75 @@ pub fn with<T,R>(
4950
*/
5051
#[inline(always)]
5152
pub fn swap<T>(x: &mut T, y: &mut T) {
52-
*x <-> *y;
53+
unsafe {
54+
swap_ptr(ptr::to_mut_unsafe_ptr(x), ptr::to_mut_unsafe_ptr(y));
55+
}
56+
}
57+
58+
/**
59+
* Swap the values at two mutable locations of the same type, without
60+
* deinitialising or copying either one.
61+
*/
62+
#[inline]
63+
#[cfg(not(stage0))]
64+
pub unsafe fn swap_ptr<T>(x: *mut T, y: *mut T) {
65+
if x == y { return }
66+
67+
// Give ourselves some scratch space to work with
68+
let mut tmp: T = intrinsics::uninit();
69+
let t = ptr::to_mut_unsafe_ptr(&mut tmp);
70+
71+
// Perform the swap
72+
ptr::copy_memory(t, x, 1);
73+
ptr::copy_memory(x, y, 1);
74+
ptr::copy_memory(y, t, 1);
75+
76+
// y and t now point to the same thing, but we need to completely forget t
77+
// because it's no longer relevant.
78+
cast::forget(tmp);
79+
}
80+
81+
/**
82+
* Swap the values at two mutable locations of the same type, without
83+
* deinitialising or copying either one.
84+
*/
85+
#[inline]
86+
#[cfg(stage0)]
87+
pub unsafe fn swap_ptr<T>(x: *mut T, y: *mut T) {
88+
if x == y { return }
89+
90+
// Give ourselves some scratch space to work with
91+
let mut tmp: T = intrinsics::init();
92+
let t = ptr::to_mut_unsafe_ptr(&mut tmp);
93+
94+
// Perform the swap
95+
ptr::copy_memory(t, x, 1);
96+
ptr::copy_memory(x, y, 1);
97+
ptr::copy_memory(y, t, 1);
98+
99+
// y and t now point to the same thing, but we need to completely forget t
100+
// because it's no longer relevant.
101+
cast::forget(tmp);
102+
}
103+
104+
/**
105+
* Replace the value at a mutable location with a new one, returning the old
106+
* value, without deinitialising or copying either one.
107+
*/
108+
#[inline(always)]
109+
pub fn replace<T>(dest: &mut T, mut src: T) -> T {
110+
swap(dest, &mut src);
111+
src
53112
}
54113

55114
/**
56115
* Replace the value at a mutable location with a new one, returning the old
57116
* value, without deinitialising or copying either one.
58117
*/
59118
#[inline(always)]
60-
pub fn replace<T>(dest: &mut T, src: T) -> T {
61-
let mut tmp = src;
62-
swap(dest, &mut tmp);
63-
tmp
119+
pub unsafe fn replace_ptr<T>(dest: *mut T, mut src: T) -> T {
120+
swap_ptr(dest, ptr::to_mut_unsafe_ptr(&mut src));
121+
src
64122
}
65123

66124
/// A non-copyable dummy type.

branches/auto/src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use middle::ty;
2020
use middle;
2121
use util::ppaux::ty_to_str;
2222

23-
use std::flate;
23+
use core::flate;
2424
use core::hash::HashUtil;
2525
use core::hashmap::HashMap;
2626
use std::serialize::Encodable;

branches/auto/src/librustc/metadata/loader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use syntax::parse::token::ident_interner;
2222
use syntax::print::pprust;
2323
use syntax::{ast, attr};
2424

25-
use std::flate;
25+
use core::flate;
2626
use core::os::consts::{macos, freebsd, linux, android, win32};
2727

2828
pub enum os {

branches/auto/src/libstd/std.rc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ pub mod complex;
107107
pub mod stats;
108108
pub mod semver;
109109
pub mod fileinput;
110-
pub mod flate;
111110

112111
#[cfg(unicode)]
113112
mod unicode;

0 commit comments

Comments
 (0)