Skip to content

Commit 9508035

Browse files
committed
---
yaml --- r: 22448 b: refs/heads/master c: fdf0c1b h: refs/heads/master v: v3
1 parent f9bf538 commit 9508035

File tree

8 files changed

+142
-22
lines changed

8 files changed

+142
-22
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: c0961bb88fe274795725c871871d7053429ae22e
2+
refs/heads/master: fdf0c1b353393ff34b1dee6edfbfece13f7c3093
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/libcore/dvec.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,32 @@ export unwrap;
4646
* pointers achieved about 103 million pushes/second. Using an option
4747
* type could only produce 47 million pushes/second.
4848
*/
49-
type dvec<A> = {
49+
type dvec_<A> = {
5050
mut data: ~[mut A]
5151
};
5252

53+
enum dvec<A> {
54+
dvec_(dvec_<A>)
55+
}
56+
5357
/// Creates a new, empty dvec
5458
fn dvec<A>() -> dvec<A> {
55-
{mut data: ~[mut]}
59+
dvec_({mut data: ~[mut]})
5660
}
5761

5862
/// Creates a new dvec with a single element
5963
fn from_elem<A>(+e: A) -> dvec<A> {
60-
{mut data: ~[mut e]}
64+
dvec_({mut data: ~[mut e]})
6165
}
6266

6367
/// Creates a new dvec with the contents of a vector
6468
fn from_vec<A>(+v: ~[mut A]) -> dvec<A> {
65-
{mut data: v}
69+
dvec_({mut data: v})
6670
}
6771

6872
/// Consumes the vector and returns its contents
6973
fn unwrap<A>(-d: dvec<A>) -> ~[mut A] {
70-
let {data: v} <- d;
74+
let dvec_({data: v}) <- d;
7175
ret v;
7276
}
7377

trunk/src/libcore/iter-trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl extensions<A> of iter::base_iter<A> for IMPL_T<A> {
2121
}
2222
}
2323

24-
impl extensions<A:copy> for IMPL_T<A> {
24+
impl extensions<A:copy> of iter::copyable_iter<A> for IMPL_T<A> {
2525
fn filter_to_vec(pred: fn(A) -> bool) -> ~[A] {
2626
iter::filter_to_vec(self, pred)
2727
}

trunk/src/libcore/iter.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ iface times {
77
fn times(it: fn() -> bool);
88
}
99

10+
trait copyable_iter<A:copy> {
11+
fn filter_to_vec(pred: fn(A) -> bool) -> ~[A];
12+
fn map_to_vec<B>(op: fn(A) -> B) -> ~[B];
13+
fn to_vec() -> ~[A];
14+
fn min() -> A;
15+
fn max() -> A;
16+
fn find(p: fn(A) -> bool) -> option<A>;
17+
}
18+
1019
fn eachi<A,IA:base_iter<A>>(self: IA, blk: fn(uint, A) -> bool) {
1120
let mut i = 0u;
1221
for self.each |a| {

trunk/src/libcore/pipes.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,24 @@ enum state {
1111
terminated
1212
}
1313

14-
type packet_header = {
14+
type packet_header_ = {
1515
mut state: state,
1616
mut blocked_task: option<*rust_task>,
1717
};
1818

19-
type packet<T: send> = {
19+
enum packet_header {
20+
packet_header_(packet_header_)
21+
}
22+
23+
type packet_<T:send> = {
2024
header: packet_header,
2125
mut payload: option<T>
2226
};
2327

28+
enum packet<T:send> {
29+
packet_(packet_<T>)
30+
}
31+
2432
fn packet<T: send>() -> *packet<T> unsafe {
2533
let p: *packet<T> = unsafe::transmute(~{
2634
header: {
@@ -428,8 +436,17 @@ proto! streamp {
428436
}
429437
}
430438

431-
type chan<T:send> = { mut endp: option<streamp::client::open<T>> };
432-
type port<T:send> = { mut endp: option<streamp::server::open<T>> };
439+
type chan_<T:send> = { mut endp: option<streamp::client::open<T>> };
440+
441+
enum chan<T:send> {
442+
chan_(chan_<T>)
443+
}
444+
445+
type port_<T:send> = { mut endp: option<streamp::server::open<T>> };
446+
447+
enum port<T:send> {
448+
port_(port_<T>)
449+
}
433450

434451
fn stream<T:send>() -> (chan<T>, port<T>) {
435452
let (c, s) = streamp::init();
@@ -439,7 +456,7 @@ fn stream<T:send>() -> (chan<T>, port<T>) {
439456
unsafe { let y <- *ptr::addr_of(x); y }]
440457
];
441458

442-
({ mut endp: some(c) }, { mut endp: some(s) })
459+
(chan_({ mut endp: some(c) }), port_({ mut endp: some(s) }))
443460
}
444461

445462
impl chan<T: send> for chan<T> {

trunk/src/libcore/ptr.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,13 @@ unsafe fn memset<T>(dst: *mut T, c: int, count: uint) {
123123
libc_::memset(dst as *c_void, c as libc::c_int, n as size_t);
124124
}
125125

126+
trait ptr {
127+
pure fn is_null() -> bool;
128+
pure fn is_not_null() -> bool;
129+
}
130+
126131
/// Extension methods for pointers
127-
impl extensions<T> for *T {
132+
impl extensions<T> of ptr for *T {
128133
/// Returns true if the pointer is equal to the null pointer.
129134
pure fn is_null() -> bool { is_null(self) }
130135

trunk/src/libcore/str.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,8 +1882,15 @@ mod unsafe {
18821882

18831883
}
18841884

1885+
trait unique_str {
1886+
fn trim() -> self;
1887+
fn trim_left() -> self;
1888+
fn trim_right() -> self;
1889+
pure fn +(rhs: str/&) -> self;
1890+
}
1891+
18851892
/// Extension methods for strings
1886-
impl extensions for str {
1893+
impl extensions of unique_str for str {
18871894
/// Returns a string with leading and trailing whitespace removed
18881895
#[inline]
18891896
fn trim() -> str { trim(self) }
@@ -1901,8 +1908,35 @@ impl extensions for str {
19011908
}
19021909
}
19031910

1911+
trait str_slice {
1912+
fn all(it: fn(char) -> bool) -> bool;
1913+
fn any(it: fn(char) -> bool) -> bool;
1914+
fn contains(needle: str/&a) -> bool;
1915+
fn contains_char(needle: char) -> bool;
1916+
fn each(it: fn(u8) -> bool);
1917+
fn eachi(it: fn(uint, u8) -> bool);
1918+
fn each_char(it: fn(char) -> bool);
1919+
fn each_chari(it: fn(uint, char) -> bool);
1920+
fn ends_with(needle: str/&) -> bool;
1921+
fn is_empty() -> bool;
1922+
fn is_not_empty() -> bool;
1923+
fn is_whitespace() -> bool;
1924+
fn is_alphanumeric() -> bool;
1925+
pure fn len() -> uint;
1926+
fn slice(begin: uint, end: uint) -> str;
1927+
fn split(sepfn: fn(char) -> bool) -> ~[str];
1928+
fn split_char(sep: char) -> ~[str];
1929+
fn split_str(sep: str/&a) -> ~[str];
1930+
fn starts_with(needle: str/&a) -> bool;
1931+
fn substr(begin: uint, n: uint) -> str;
1932+
fn to_lower() -> str;
1933+
fn to_upper() -> str;
1934+
fn escape_default() -> str;
1935+
fn escape_unicode() -> str;
1936+
}
1937+
19041938
/// Extension methods for strings
1905-
impl extensions/& for str/& {
1939+
impl extensions/& of str_slice for str/& {
19061940
/**
19071941
* Return true if a predicate matches all characters or if the string
19081942
* contains no characters

trunk/src/libcore/vec.rs

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,22 +1181,32 @@ pure fn unpack_mut_slice<T,U>(s: &[mut T],
11811181
}
11821182
}
11831183

1184-
impl extensions<T: copy> for ~[T] {
1184+
trait vec_concat<T> {
1185+
pure fn +(rhs: &[const T]) -> self;
1186+
}
1187+
1188+
impl extensions<T: copy> of vec_concat<T> for ~[T] {
11851189
#[inline(always)]
11861190
pure fn +(rhs: &[const T]) -> ~[T] {
11871191
append(self, rhs)
11881192
}
11891193
}
11901194

1191-
impl extensions<T: copy> for ~[mut T] {
1195+
impl extensions<T: copy> of vec_concat<T> for ~[mut T] {
11921196
#[inline(always)]
11931197
pure fn +(rhs: &[const T]) -> ~[mut T] {
11941198
append_mut(self, rhs)
11951199
}
11961200
}
11971201

1202+
trait const_vector {
1203+
pure fn is_empty() -> bool;
1204+
pure fn is_not_empty() -> bool;
1205+
pure fn len() -> uint;
1206+
}
1207+
11981208
/// Extension methods for vectors
1199-
impl extensions/&<T> for &[const T] {
1209+
impl extensions/&<T> of const_vector for &[const T] {
12001210
/// Returns true if a vector contains no elements
12011211
#[inline]
12021212
pure fn is_empty() -> bool { is_empty(self) }
@@ -1208,8 +1218,16 @@ impl extensions/&<T> for &[const T] {
12081218
pure fn len() -> uint { len(self) }
12091219
}
12101220

1221+
trait copyable_vector<T> {
1222+
pure fn head() -> T;
1223+
pure fn init() -> ~[T];
1224+
pure fn last() -> T;
1225+
pure fn slice(start: uint, end: uint) -> ~[T];
1226+
pure fn tail() -> ~[T];
1227+
}
1228+
12111229
/// Extension methods for vectors
1212-
impl extensions/&<T: copy> for &[const T] {
1230+
impl extensions/&<T: copy> of copyable_vector<T> for &[const T] {
12131231
/// Returns the first element of a vector
12141232
#[inline]
12151233
pure fn head() -> T { head(self) }
@@ -1227,8 +1245,26 @@ impl extensions/&<T: copy> for &[const T] {
12271245
pure fn tail() -> ~[T] { tail(self) }
12281246
}
12291247

1248+
trait immutable_vector/&<T> {
1249+
pure fn foldr<U: copy>(z: U, p: fn(T, U) -> U) -> U;
1250+
pure fn iter(f: fn(T));
1251+
pure fn iteri(f: fn(uint, T));
1252+
pure fn position(f: fn(T) -> bool) -> option<uint>;
1253+
pure fn position_elem(x: T) -> option<uint>;
1254+
pure fn riter(f: fn(T));
1255+
pure fn riteri(f: fn(uint, T));
1256+
pure fn rposition(f: fn(T) -> bool) -> option<uint>;
1257+
pure fn rposition_elem(x: T) -> option<uint>;
1258+
pure fn map<U>(f: fn(T) -> U) -> ~[U];
1259+
pure fn mapi<U>(f: fn(uint, T) -> U) -> ~[U];
1260+
fn map_r<U>(f: fn(x: &self.T) -> U) -> ~[U];
1261+
pure fn alli(f: fn(uint, T) -> bool) -> bool;
1262+
pure fn flat_map<U>(f: fn(T) -> ~[U]) -> ~[U];
1263+
pure fn filter_map<U: copy>(f: fn(T) -> option<U>) -> ~[U];
1264+
}
1265+
12301266
/// Extension methods for vectors
1231-
impl extensions/&<T> for &[T] {
1267+
impl extensions/&<T> of immutable_vector<T> for &[T] {
12321268
/// Reduce a vector from right to left
12331269
#[inline]
12341270
pure fn foldr<U: copy>(z: U, p: fn(T, U) -> U) -> U { foldr(self, z, p) }
@@ -1336,8 +1372,14 @@ impl extensions/&<T> for &[T] {
13361372
}
13371373
}
13381374

1375+
trait immutable_copyable_vector<T> {
1376+
pure fn filter(f: fn(T) -> bool) -> ~[T];
1377+
pure fn find(f: fn(T) -> bool) -> option<T>;
1378+
pure fn rfind(f: fn(T) -> bool) -> option<T>;
1379+
}
1380+
13391381
/// Extension methods for vectors
1340-
impl extensions/&<T: copy> for &[T] {
1382+
impl extensions/&<T: copy> of immutable_copyable_vector<T> for &[T] {
13411383
/**
13421384
* Construct a new vector from the elements of a vector for which some
13431385
* predicate holds.
@@ -1510,7 +1552,16 @@ impl extensions/&<A> of iter::base_iter<A> for &[const A] {
15101552
fn contains(x: A) -> bool { iter::contains(self, x) }
15111553
fn count(x: A) -> uint { iter::count(self, x) }
15121554
}
1513-
impl extensions/&<A:copy> for &[const A] {
1555+
1556+
trait iter_trait_extensions<A> {
1557+
fn filter_to_vec(pred: fn(A) -> bool) -> ~[A];
1558+
fn map_to_vec<B>(op: fn(A) -> B) -> ~[B];
1559+
fn to_vec() -> ~[A];
1560+
fn min() -> A;
1561+
fn max() -> A;
1562+
}
1563+
1564+
impl extensions/&<A:copy> of iter_trait_extensions<A> for &[const A] {
15141565
fn filter_to_vec(pred: fn(A) -> bool) -> ~[A] {
15151566
iter::filter_to_vec(self, pred)
15161567
}

0 commit comments

Comments
 (0)