Skip to content

Commit c2c8e5e

Browse files
committed
---
yaml --- r: 140687 b: refs/heads/try2 c: 7d22437 h: refs/heads/master i: 140685: f0d5f4e 140683: e43ac06 140679: 0ecb0b6 140671: d49bf29 v: v3
1 parent 8d96c9c commit c2c8e5e

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
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: c49cf8b3300a97201058debd63b0f7aef34d3c35
8+
refs/heads/try2: 7d22437ecdc5b52f8517ffde6207347739b26553
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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/try2/src/libstd/flate.rs renamed to branches/try2/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/try2/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/try2/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/try2/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/try2/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)