2
2
3
3
use ptr:: addr_of;
4
4
5
+ export init_op;
6
+ export capacity;
7
+ export build_sized, build, build_sized_opt;
8
+ export map;
9
+ export from_fn, from_elem;
10
+ export raw;
11
+ export traits;
12
+
5
13
/// Code for dealing with @-vectors. This is pretty incomplete, and
6
14
/// contains a bunch of duplication from the code for ~-vectors.
7
15
8
16
#[ abi = "cdecl" ]
9
17
extern mod rustrt {
10
- pub fn vec_reserve_shared_actual ( ++t : * sys:: TypeDesc ,
18
+ #[ legacy_exports] ;
19
+ fn vec_reserve_shared_actual ( ++t : * sys:: TypeDesc ,
11
20
++v : * * vec:: raw:: VecRepr ,
12
21
++n : libc:: size_t ) ;
13
22
}
14
23
15
24
#[ abi = "rust-intrinsic" ]
16
25
extern mod rusti {
17
- pub fn move_val_init < T > ( & dst: T , -src : T ) ;
26
+ #[ legacy_exports] ;
27
+ fn move_val_init < T > ( & dst: T , -src : T ) ;
18
28
}
19
29
20
30
/// Returns the number of elements the vector can hold without reallocating
21
31
#[ inline( always) ]
22
- pub pure fn capacity < T > ( & & v: @[ const T ] ) -> uint {
32
+ pure fn capacity < T > ( & & v: @[ const T ] ) -> uint {
23
33
unsafe {
24
34
let repr: * * raw :: VecRepr =
25
35
:: cast:: reinterpret_cast ( & addr_of ( v) ) ;
@@ -40,8 +50,7 @@ pub pure fn capacity<T>(&&v: @[const T]) -> uint {
40
50
* onto the vector being constructed.
41
51
*/
42
52
#[ inline( always) ]
43
- pub pure fn build_sized < A > ( size : uint ,
44
- builder : fn ( push : pure fn( +A ) ) ) -> @[ A ] {
53
+ pure fn build_sized < A > ( size : uint , builder : fn ( push : pure fn( +A ) ) ) -> @[ A ] {
45
54
let mut vec = @[ ] ;
46
55
unsafe { raw:: reserve ( vec, size) ; }
47
56
builder ( |+x| unsafe { raw:: push ( vec, move x) } ) ;
@@ -59,7 +68,7 @@ pub pure fn build_sized<A>(size: uint,
59
68
* onto the vector being constructed.
60
69
*/
61
70
#[ inline( always) ]
62
- pub pure fn build < A > ( builder : fn ( push : pure fn( +A ) ) ) -> @[ A ] {
71
+ pure fn build < A > ( builder : fn ( push : pure fn( +A ) ) ) -> @[ A ] {
63
72
build_sized ( 4 , builder)
64
73
}
65
74
@@ -76,7 +85,7 @@ pub pure fn build<A>(builder: fn(push: pure fn(+A))) -> @[A] {
76
85
* onto the vector being constructed.
77
86
*/
78
87
#[ inline( always) ]
79
- pub pure fn build_sized_opt < A > ( size : Option < uint > ,
88
+ pure fn build_sized_opt < A > ( size : Option < uint > ,
80
89
builder : fn ( push : pure fn( +A ) ) ) -> @[ A ] {
81
90
build_sized ( size. get_default ( 4 ) , builder)
82
91
}
@@ -92,7 +101,7 @@ pure fn append<T: Copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
92
101
93
102
94
103
/// Apply a function to each element of a vector and return the results
95
- pub pure fn map < T , U > ( v : & [ T ] , f : fn ( T ) -> U ) -> @[ U ] {
104
+ pure fn map < T , U > ( v : & [ T ] , f : fn ( T ) -> U ) -> @[ U ] {
96
105
do build_sized ( v. len ( ) ) |push| {
97
106
for vec:: each( v) |elem| {
98
107
push ( f ( * elem) ) ;
@@ -106,7 +115,7 @@ pub pure fn map<T, U>(v: &[T], f: fn(T) -> U) -> @[U] {
106
115
* Creates an immutable vector of size `n_elts` and initializes the elements
107
116
* to the value returned by the function `op`.
108
117
*/
109
- pub pure fn from_fn < T > ( n_elts : uint , op : iter:: InitOp < T > ) -> @[ T ] {
118
+ pure fn from_fn < T > ( n_elts : uint , op : iter:: InitOp < T > ) -> @[ T ] {
110
119
do build_sized ( n_elts) |push| {
111
120
let mut i: uint = 0 u;
112
121
while i < n_elts { push ( op ( i) ) ; i += 1 u; }
@@ -119,7 +128,7 @@ pub pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> @[T] {
119
128
* Creates an immutable vector of size `n_elts` and initializes the elements
120
129
* to the value `t`.
121
130
*/
122
- pub pure fn from_elem < T : Copy > ( n_elts : uint , t : T ) -> @[ T ] {
131
+ pure fn from_elem < T : Copy > ( n_elts : uint , t : T ) -> @[ T ] {
123
132
do build_sized ( n_elts) |push| {
124
133
let mut i: uint = 0 u;
125
134
while i < n_elts { push ( t) ; i += 1 u; }
@@ -128,6 +137,7 @@ pub pure fn from_elem<T: Copy>(n_elts: uint, t: T) -> @[T] {
128
137
129
138
#[ cfg( notest) ]
130
139
mod traits {
140
+ #[ legacy_exports] ;
131
141
#[ cfg( stage0) ]
132
142
impl < T : Copy > @[ T ] : Add < & [ const T ] , @[ T ] > {
133
143
#[ inline( always) ]
@@ -149,9 +159,10 @@ mod traits {
149
159
mod traits {
150
160
#[ legacy_exports] ; }
151
161
152
- pub mod raw {
153
- pub type VecRepr = vec:: raw:: VecRepr ;
154
- pub type SliceRepr = vec:: raw:: SliceRepr ;
162
+ mod raw {
163
+ #[ legacy_exports] ;
164
+ type VecRepr = vec:: raw:: VecRepr ;
165
+ type SliceRepr = vec:: raw:: SliceRepr ;
155
166
156
167
/**
157
168
* Sets the length of a vector
@@ -161,13 +172,13 @@ pub mod raw {
161
172
* the vector is actually the specified size.
162
173
*/
163
174
#[ inline( always) ]
164
- pub unsafe fn set_len < T > ( & & v: @[ const T ] , new_len : uint ) {
175
+ unsafe fn set_len < T > ( & & v: @[ const T ] , new_len : uint ) {
165
176
let repr: * * VecRepr = :: cast:: reinterpret_cast ( & addr_of ( v) ) ;
166
177
( * * repr) . unboxed . fill = new_len * sys:: size_of :: < T > ( ) ;
167
178
}
168
179
169
180
#[ inline( always) ]
170
- pub unsafe fn push < T > ( & v: @[ const T ] , +initval : T ) {
181
+ unsafe fn push < T > ( & v: @[ const T ] , +initval : T ) {
171
182
let repr: * * VecRepr = :: cast:: reinterpret_cast ( & addr_of ( v) ) ;
172
183
let fill = ( * * repr) . unboxed . fill ;
173
184
if ( * * repr) . unboxed . alloc > fill {
@@ -204,7 +215,7 @@ pub mod raw {
204
215
* * v - A vector
205
216
* * n - The number of elements to reserve space for
206
217
*/
207
- pub unsafe fn reserve < T > ( & v: @[ const T ] , n : uint ) {
218
+ unsafe fn reserve < T > ( & v: @[ const T ] , n : uint ) {
208
219
// Only make the (slow) call into the runtime if we have to
209
220
if capacity ( v) < n {
210
221
let ptr = addr_of ( v) as * * VecRepr ;
@@ -228,7 +239,7 @@ pub mod raw {
228
239
* * v - A vector
229
240
* * n - The number of elements to reserve space for
230
241
*/
231
- pub unsafe fn reserve_at_least < T > ( & v: @[ const T ] , n : uint ) {
242
+ unsafe fn reserve_at_least < T > ( & v: @[ const T ] , n : uint ) {
232
243
reserve ( v, uint:: next_power_of_two ( n) ) ;
233
244
}
234
245
0 commit comments