Skip to content

Commit c995a62

Browse files
committed
librustc: WIP patch for using the return value.
1 parent 7720c15 commit c995a62

26 files changed

+778
-406
lines changed

src/libcore/core.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub use str::{StrSlice};
9595
pub use container::{Container, Mutable};
9696
pub use vec::{CopyableVector, ImmutableVector};
9797
pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
98-
pub use vec::{OwnedVector, OwnedCopyableVector};
98+
pub use vec::{OwnedVector, OwnedCopyableVector, MutableVector};
9999
pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
100100
pub use iter::{CopyableOrderedIter, CopyableNonstrictIter, Times};
101101
pub use iter::{ExtendedMutableIter};

src/libcore/hashmap.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use container::{Container, Mutable, Map, Set};
1717
use cmp::{Eq, Equiv};
1818
use hash::Hash;
19-
use to_bytes::IterBytes;
2019
use iter::BaseIter;
2120
use hash::Hash;
2221
use iter;
@@ -72,7 +71,7 @@ fn linear_map_with_capacity_and_keys<K:Eq + Hash,V>(
7271
}
7372
}
7473

75-
priv impl<K:Hash + IterBytes + Eq,V> HashMap<K, V> {
74+
priv impl<K:Hash + Eq,V> HashMap<K, V> {
7675
#[inline(always)]
7776
fn to_bucket(&self, h: uint) -> uint {
7877
// A good hash function with entropy spread over all of the
@@ -111,9 +110,8 @@ priv impl<K:Hash + IterBytes + Eq,V> HashMap<K, V> {
111110
}
112111

113112
#[inline(always)]
114-
fn bucket_for_key_equiv<Q:Hash + IterBytes + Equiv<K>>(&self,
115-
k: &Q)
116-
-> SearchResult {
113+
fn bucket_for_key_equiv<Q:Hash + Equiv<K>>(&self, k: &Q)
114+
-> SearchResult {
117115
let hash = k.hash_keyed(self.k0, self.k1) as uint;
118116
self.bucket_for_key_with_hash_equiv(hash, k)
119117
}
@@ -303,15 +301,15 @@ priv impl<K:Hash + IterBytes + Eq,V> HashMap<K, V> {
303301
}
304302
}
305303
306-
impl<K:Hash + IterBytes + Eq,V> Container for HashMap<K, V> {
304+
impl<K:Hash + Eq,V> Container for HashMap<K, V> {
307305
/// Return the number of elements in the map
308306
fn len(&const self) -> uint { self.size }
309307
310308
/// Return true if the map contains no elements
311309
fn is_empty(&const self) -> bool { self.len() == 0 }
312310
}
313311
314-
impl<K:Hash + IterBytes + Eq,V> Mutable for HashMap<K, V> {
312+
impl<K:Hash + Eq,V> Mutable for HashMap<K, V> {
315313
/// Clear the map, removing all key-value pairs.
316314
fn clear(&mut self) {
317315
for uint::range(0, self.buckets.len()) |idx| {
@@ -321,7 +319,7 @@ impl<K:Hash + IterBytes + Eq,V> Mutable for HashMap<K, V> {
321319
}
322320
}
323321
324-
impl<K:Hash + IterBytes + Eq,V> Map<K, V> for HashMap<K, V> {
322+
impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
325323
/// Return true if the map contains a value for the specified key
326324
fn contains_key(&self, k: &K) -> bool {
327325
match self.bucket_for_key(k) {
@@ -458,7 +456,7 @@ impl<K:Hash + IterBytes + Eq,V> Map<K, V> for HashMap<K, V> {
458456
}
459457
}
460458
461-
pub impl<K: Hash + IterBytes + Eq, V> HashMap<K, V> {
459+
pub impl<K: Hash + Eq, V> HashMap<K, V> {
462460
/// Create an empty HashMap
463461
fn new() -> HashMap<K, V> {
464462
HashMap::with_capacity(INITIAL_CAPACITY)
@@ -669,8 +667,7 @@ pub impl<K: Hash + IterBytes + Eq, V> HashMap<K, V> {
669667

670668
/// Return true if the map contains a value for the specified key,
671669
/// using equivalence
672-
fn contains_key_equiv<Q:Hash + IterBytes + Equiv<K>>(&self, key: &Q)
673-
-> bool {
670+
fn contains_key_equiv<Q:Hash + Equiv<K>>(&self, key: &Q) -> bool {
674671
match self.bucket_for_key_equiv(key) {
675672
FoundEntry(_) => {true}
676673
TableFull | FoundHole(_) => {false}
@@ -680,8 +677,7 @@ pub impl<K: Hash + IterBytes + Eq, V> HashMap<K, V> {
680677
/// Return the value corresponding to the key in the map, using
681678
/// equivalence
682679
#[cfg(stage0)]
683-
fn find_equiv<Q:Hash + IterBytes + Equiv<K>>(&self, k: &Q)
684-
-> Option<&'self V> {
680+
fn find_equiv<Q:Hash + Equiv<K>>(&self, k: &Q) -> Option<&'self V> {
685681
match self.bucket_for_key_equiv(k) {
686682
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
687683
TableFull | FoundHole(_) => None,
@@ -693,17 +689,15 @@ pub impl<K: Hash + IterBytes + Eq, V> HashMap<K, V> {
693689
#[cfg(stage1)]
694690
#[cfg(stage2)]
695691
#[cfg(stage3)]
696-
fn find_equiv<'a, Q:Hash + IterBytes + Equiv<K>>(
697-
&'a self, k: &Q) -> Option<&'a V>
698-
{
692+
fn find_equiv<'a, Q:Hash + Equiv<K>>(&'a self, k: &Q) -> Option<&'a V> {
699693
match self.bucket_for_key_equiv(k) {
700694
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
701695
TableFull | FoundHole(_) => None,
702696
}
703697
}
704698
}
705699

706-
impl<K:Hash + IterBytes + Eq,V:Eq> Eq for HashMap<K, V> {
700+
impl<K:Hash + Eq,V:Eq> Eq for HashMap<K, V> {
707701
fn eq(&self, other: &HashMap<K, V>) -> bool {
708702
if self.len() != other.len() { return false; }
709703

@@ -724,31 +718,31 @@ pub struct HashSet<T> {
724718
priv map: HashMap<T, ()>
725719
}
726720

727-
impl<T:Hash + IterBytes + Eq> BaseIter<T> for HashSet<T> {
721+
impl<T:Hash + Eq> BaseIter<T> for HashSet<T> {
728722
/// Visit all values in order
729723
fn each(&self, f: &fn(&T) -> bool) { self.map.each_key(f) }
730724
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
731725
}
732726

733-
impl<T:Hash + IterBytes + Eq> Eq for HashSet<T> {
727+
impl<T:Hash + Eq> Eq for HashSet<T> {
734728
fn eq(&self, other: &HashSet<T>) -> bool { self.map == other.map }
735729
fn ne(&self, other: &HashSet<T>) -> bool { self.map != other.map }
736730
}
737731

738-
impl<T:Hash + IterBytes + Eq> Container for HashSet<T> {
732+
impl<T:Hash + Eq> Container for HashSet<T> {
739733
/// Return the number of elements in the set
740734
fn len(&const self) -> uint { self.map.len() }
741735

742736
/// Return true if the set contains no elements
743737
fn is_empty(&const self) -> bool { self.map.is_empty() }
744738
}
745739

746-
impl<T:Hash + IterBytes + Eq> Mutable for HashSet<T> {
740+
impl<T:Hash + Eq> Mutable for HashSet<T> {
747741
/// Clear the set, removing all values.
748742
fn clear(&mut self) { self.map.clear() }
749743
}
750744

751-
impl<T:Hash + IterBytes + Eq> Set<T> for HashSet<T> {
745+
impl<T:Hash + Eq> Set<T> for HashSet<T> {
752746
/// Return true if the set contains a value
753747
fn contains(&self, value: &T) -> bool { self.map.contains_key(value) }
754748

@@ -816,7 +810,7 @@ impl<T:Hash + IterBytes + Eq> Set<T> for HashSet<T> {
816810
}
817811
}
818812

819-
pub impl <T:Hash + IterBytes + Eq> HashSet<T> {
813+
pub impl <T:Hash + Eq> HashSet<T> {
820814
/// Create an empty HashSet
821815
fn new() -> HashSet<T> {
822816
HashSet::with_capacity(INITIAL_CAPACITY)

src/libcore/libc.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,9 +1097,12 @@ pub mod funcs {
10971097
unsafe fn setbuf(stream: *FILE, buf: *c_char);
10981098
// Omitted: printf and scanf variants.
10991099
unsafe fn fgetc(stream: *FILE) -> c_int;
1100+
#[fast_ffi]
11001101
unsafe fn fgets(buf: *mut c_char, n: c_int,
11011102
stream: *FILE) -> *c_char;
1103+
#[fast_ffi]
11021104
unsafe fn fputc(c: c_int, stream: *FILE) -> c_int;
1105+
#[fast_ffi]
11031106
unsafe fn fputs(s: *c_char, stream: *FILE) -> *c_char;
11041107
// Omitted: getc, getchar (might be macros).
11051108

@@ -1263,6 +1266,7 @@ pub mod funcs {
12631266
unsafe fn pclose(stream: *FILE) -> c_int;
12641267

12651268
#[link_name = "_fdopen"]
1269+
#[fast_ffi]
12661270
unsafe fn fdopen(fd: c_int, mode: *c_char) -> *FILE;
12671271

12681272
#[link_name = "_fileno"]

src/libcore/num/int-template.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,4 +503,4 @@ mod tests {
503503
fn test_range_step_zero_step() {
504504
for range_step(0,10,0) |_i| {}
505505
}
506-
}
506+
}

src/libcore/num/uint-template.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,4 +474,4 @@ mod tests {
474474
fn test_range_step_zero_step_down() {
475475
for range_step(0,-10,0) |_i| {}
476476
}
477-
}
477+
}

src/libcore/prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub use to_str::ToStr;
4646
pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps};
4747
pub use vec::{CopyableVector, ImmutableVector};
4848
pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
49-
pub use vec::{OwnedVector, OwnedCopyableVector};
49+
pub use vec::{OwnedVector, OwnedCopyableVector, MutableVector};
5050
pub use io::{Reader, ReaderUtil, Writer, WriterUtil};
5151

5252
/* Reexported runtime types */

src/libcore/str.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,15 @@ pub fn byte_slice<T>(s: &str, f: &fn(v: &[u8]) -> T) -> T {
430430
}
431431
}
432432

433+
/// Work with the string as a byte slice, not including trailing null, without
434+
/// a callback.
435+
#[inline(always)]
436+
pub fn byte_slice_no_callback<'a>(s: &'a str) -> &'a [u8] {
437+
unsafe {
438+
cast::transmute(s)
439+
}
440+
}
441+
433442
/// Convert a string to a unique vector of characters
434443
pub fn to_chars(s: &str) -> ~[char] {
435444
let mut buf = ~[];

src/libcore/vec.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ pub fn same_length<T, U>(xs: &const [T], ys: &const [U]) -> bool {
7676
* * v - A vector
7777
* * n - The number of elements to reserve space for
7878
*/
79+
#[inline]
7980
pub fn reserve<T>(v: &mut ~[T], n: uint) {
8081
// Only make the (slow) call into the runtime if we have to
8182
use managed;
@@ -1831,6 +1832,7 @@ pub trait ImmutableVector<T> {
18311832
fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool;
18321833
fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U];
18331834
fn filter_mapped<U:Copy>(&self, f: &fn(t: &T) -> Option<U>) -> ~[U];
1835+
unsafe fn unsafe_ref(&self, index: uint) -> *T;
18341836
}
18351837

18361838
/// Extension methods for vectors
@@ -1941,6 +1943,14 @@ impl<'self,T> ImmutableVector<T> for &'self [T] {
19411943
fn filter_mapped<U:Copy>(&self, f: &fn(t: &T) -> Option<U>) -> ~[U] {
19421944
filter_mapped(*self, f)
19431945
}
1946+
1947+
/// Returns a pointer to the element at the given index, without doing
1948+
/// bounds checking.
1949+
#[inline(always)]
1950+
unsafe fn unsafe_ref(&self, index: uint) -> *T {
1951+
let (ptr, _): (*T, uint) = transmute(*self);
1952+
ptr.offset(index)
1953+
}
19441954
}
19451955

19461956
#[cfg(stage1)]
@@ -2178,9 +2188,8 @@ impl<'self,T:Copy> ImmutableCopyableVector<T> for &'self [T] {
21782188

21792189
/// Returns the element at the given index, without doing bounds checking.
21802190
#[inline(always)]
2181-
unsafe fn unsafe_get(&self, elem: uint) -> T {
2182-
let (ptr, _): (*T, uint) = transmute(*self);
2183-
*ptr.offset(elem)
2191+
unsafe fn unsafe_get(&self, index: uint) -> T {
2192+
*self.unsafe_ref(index)
21842193
}
21852194
}
21862195

@@ -2323,15 +2332,21 @@ impl<T:Eq> OwnedEqVector<T> for ~[T] {
23232332
}
23242333

23252334
pub trait MutableVector<T> {
2326-
unsafe fn unsafe_set(&self, elem: uint, val: T);
2335+
unsafe fn unsafe_mut_ref(&self, index: uint) -> *mut T;
2336+
unsafe fn unsafe_set(&self, index: uint, val: T);
23272337
}
23282338

23292339
impl<'self,T> MutableVector<T> for &'self mut [T] {
23302340
#[inline(always)]
2331-
unsafe fn unsafe_set(&self, elem: uint, val: T) {
2341+
unsafe fn unsafe_mut_ref(&self, index: uint) -> *mut T {
23322342
let pair_ptr: &(*mut T, uint) = transmute(self);
23332343
let (ptr, _) = *pair_ptr;
2334-
*ptr.offset(elem) = val;
2344+
ptr.offset(index)
2345+
}
2346+
2347+
#[inline(always)]
2348+
unsafe fn unsafe_set(&self, index: uint, val: T) {
2349+
*self.unsafe_mut_ref(index) = val;
23352350
}
23362351
}
23372352

src/librustc/back/link.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,10 @@ pub mod write {
188188
return false;
189189
}
190190

191-
pub fn run_passes(sess: Session, llmod: ModuleRef,
192-
output_type: output_type, output: &Path) {
191+
pub fn run_passes(sess: Session,
192+
llmod: ModuleRef,
193+
output_type: output_type,
194+
output: &Path) {
193195
unsafe {
194196
let opts = sess.opts;
195197
if sess.time_llvm_passes() { llvm::LLVMRustEnableTimePasses(); }

0 commit comments

Comments
 (0)