Skip to content

Commit 8b3c09a

Browse files
committed
auto merge of #5962 : pcwalton/rust/shootout, r=pcwalton
r? @brson
2 parents 6510fd9 + d2b6448 commit 8b3c09a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+3042
-1112
lines changed

src/libcore/core.rc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ 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};
101+
pub use iter::{ExtendedMutableIter};
101102

102103
pub use num::{Num, NumCast};
103104
pub use ptr::Ptr;

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/iter.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ pub trait ExtendedIter<A> {
4545
fn flat_map_to_vec<B,IB: BaseIter<B>>(&self, op: &fn(&A) -> IB) -> ~[B];
4646
}
4747

48+
pub trait ExtendedMutableIter<A> {
49+
fn eachi_mut(&mut self, blk: &fn(uint, &mut A) -> bool);
50+
}
51+
4852
pub trait EqIter<A:Eq> {
4953
fn contains(&self, x: &A) -> bool;
5054
fn count(&self, x: &A) -> uint;

src/libcore/libc.rs

Lines changed: 14 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

@@ -1109,8 +1112,10 @@ pub mod funcs {
11091112
// Omitted: putc, putchar (might be macros).
11101113
unsafe fn puts(s: *c_char) -> c_int;
11111114
unsafe fn ungetc(c: c_int, stream: *FILE) -> c_int;
1115+
#[fast_ffi]
11121116
unsafe fn fread(ptr: *mut c_void, size: size_t,
11131117
nobj: size_t, stream: *FILE) -> size_t;
1118+
#[fast_ffi]
11141119
unsafe fn fwrite(ptr: *c_void, size: size_t,
11151120
nobj: size_t, stream: *FILE) -> size_t;
11161121
unsafe fn fseek(stream: *FILE, offset: c_long,
@@ -1144,9 +1149,13 @@ pub mod funcs {
11441149
-> c_long;
11451150
unsafe fn strtoul(s: *c_char, endp: **c_char, base: c_int)
11461151
-> c_ulong;
1152+
#[fast_ffi]
11471153
unsafe fn calloc(nobj: size_t, size: size_t) -> *c_void;
1154+
#[fast_ffi]
11481155
unsafe fn malloc(size: size_t) -> *c_void;
1156+
#[fast_ffi]
11491157
unsafe fn realloc(p: *c_void, size: size_t) -> *c_void;
1158+
#[fast_ffi]
11501159
unsafe fn free(p: *c_void);
11511160
unsafe fn abort() -> !;
11521161
unsafe fn exit(status: c_int) -> !;
@@ -1257,6 +1266,7 @@ pub mod funcs {
12571266
unsafe fn pclose(stream: *FILE) -> c_int;
12581267

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

12621272
#[link_name = "_fileno"]
@@ -1340,6 +1350,7 @@ pub mod funcs {
13401350
textmode: c_int) -> c_int;
13411351

13421352
#[link_name = "_read"]
1353+
#[fast_ffi]
13431354
unsafe fn read(fd: c_int, buf: *mut c_void, count: c_uint)
13441355
-> c_int;
13451356

@@ -1350,6 +1361,7 @@ pub mod funcs {
13501361
unsafe fn unlink(c: *c_char) -> c_int;
13511362

13521363
#[link_name = "_write"]
1364+
#[fast_ffi]
13531365
unsafe fn write(fd: c_int, buf: *c_void, count: c_uint)
13541366
-> c_int;
13551367
}
@@ -1502,6 +1514,7 @@ pub mod funcs {
15021514
unsafe fn pathconf(path: *c_char, name: c_int) -> c_long;
15031515
unsafe fn pause() -> c_int;
15041516
unsafe fn pipe(fds: *mut c_int) -> c_int;
1517+
#[fast_ffi]
15051518
unsafe fn read(fd: c_int, buf: *mut c_void,
15061519
count: size_t) -> ssize_t;
15071520
unsafe fn rmdir(path: *c_char) -> c_int;
@@ -1514,6 +1527,7 @@ pub mod funcs {
15141527
unsafe fn tcgetpgrp(fd: c_int) -> pid_t;
15151528
unsafe fn ttyname(fd: c_int) -> *c_char;
15161529
unsafe fn unlink(c: *c_char) -> c_int;
1530+
#[fast_ffi]
15171531
unsafe fn write(fd: c_int, buf: *c_void, count: size_t)
15181532
-> ssize_t;
15191533
}

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub use container::{Container, Mutable, Map, Set};
3333
pub use hash::Hash;
3434
pub use iter::{BaseIter, ReverseIter, MutableIter, ExtendedIter, EqIter};
3535
pub use iter::{CopyableIter, CopyableOrderedIter, CopyableNonstrictIter};
36-
pub use iter::Times;
36+
pub use iter::{Times, ExtendedMutableIter};
3737
pub use num::{Num, NumCast};
3838
pub use path::GenericPath;
3939
pub use path::Path;
@@ -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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ pub fn from_bytes_with_null<'a>(vv: &'a [u8]) -> &'a str {
6767
return unsafe { raw::from_bytes_with_null(vv) };
6868
}
6969

70+
pub fn from_bytes_slice<'a>(vector: &'a [u8]) -> &'a str {
71+
unsafe {
72+
assert!(is_utf8(vector));
73+
let (ptr, len): (*u8, uint) = ::cast::transmute(vector);
74+
let string: &'a str = ::cast::transmute((ptr, len + 1));
75+
string
76+
}
77+
}
78+
7079
/// Copy a slice into a new unique str
7180
pub fn from_slice(s: &str) -> ~str {
7281
unsafe { raw::slice_bytes_owned(s, 0, len(s)) }
@@ -421,6 +430,15 @@ pub fn byte_slice<T>(s: &str, f: &fn(v: &[u8]) -> T) -> T {
421430
}
422431
}
423432

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+
424442
/// Convert a string to a unique vector of characters
425443
pub fn to_chars(s: &str) -> ~[char] {
426444
let mut buf = ~[];

src/libcore/unstable/lang.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ pub mod rustrt {
3535

3636
#[rust_stack]
3737
unsafe fn rust_upcall_free(ptr: *c_char);
38+
39+
#[fast_ffi]
40+
unsafe fn rust_upcall_malloc_noswitch(td: *c_char,
41+
size: uintptr_t)
42+
-> *c_char;
43+
44+
#[fast_ffi]
45+
unsafe fn rust_upcall_free_noswitch(ptr: *c_char);
3846
}
3947
}
4048

@@ -81,7 +89,7 @@ pub unsafe fn exchange_free(ptr: *c_char) {
8189
#[lang="malloc"]
8290
#[inline(always)]
8391
pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
84-
return rustrt::rust_upcall_malloc(td, size);
92+
return rustrt::rust_upcall_malloc_noswitch(td, size);
8593
}
8694

8795
// NB: Calls to free CANNOT be allowed to fail, as throwing an exception from
@@ -90,7 +98,7 @@ pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
9098
#[lang="free"]
9199
#[inline(always)]
92100
pub unsafe fn local_free(ptr: *c_char) {
93-
rustrt::rust_upcall_free(ptr);
101+
rustrt::rust_upcall_free_noswitch(ptr);
94102
}
95103

96104
#[lang="borrow_as_imm"]

0 commit comments

Comments
 (0)