File tree Expand file tree Collapse file tree 4 files changed +52
-15
lines changed Expand file tree Collapse file tree 4 files changed +52
-15
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: 404afcbb41898cf7f516f07cae3dc42e47bda46d
2
+ refs/heads/master: 133fdc11484794274b0c9b7dca9f05196d3ed01d
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
4
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5
5
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
Original file line number Diff line number Diff line change @@ -451,32 +451,30 @@ fn push_slow<T>(&v: [const T]/~, +initval: T) {
451
451
}
452
452
}
453
453
454
+ // Unchecked vector indexing
455
+ #[ inline( always) ]
456
+ unsafe fn ref < T : copy > ( v: [ const T ] /& , i: uint) -> T {
457
+ unpack_slice( v) { |p, _len|
458
+ * ptr:: offset( p, i)
459
+ }
460
+ }
461
+
454
462
#[ inline( always) ]
455
463
fn push_all<T : copy>( & v: [ const T ] /~, rhs: [ const T ] /& ) {
456
464
reserve( v, v. len( ) + rhs. len( ) ) ;
457
465
458
466
for uint:: range( 0 u, rhs. len( ) ) { |i|
459
- push( v, rhs[ i ] ) ;
467
+ push( v, unsafe { ref ( rhs, i ) } )
460
468
}
461
469
}
462
470
463
471
// Appending
464
472
#[ inline( always) ]
465
473
pure fn append<T : copy>( lhs: [ T ] /& , rhs: [ const T ] /& ) -> [ T ] /~ {
466
474
let mut v = [ ] /~;
467
- let mut i = 0 u;
468
- while i < lhs. len( ) {
469
- unsafe { // This is impure, but it appears pure to the caller.
470
- push( v, lhs[ i] ) ;
471
- }
472
- i += 1 u;
473
- }
474
- i = 0 u;
475
- while i < rhs. len( ) {
476
- unsafe { // This is impure, but it appears pure to the caller.
477
- push( v, rhs[ i] ) ;
478
- }
479
- i += 1 u;
475
+ unchecked {
476
+ push_all( v, lhs) ;
477
+ push_all( v, rhs) ;
480
478
}
481
479
ret v;
482
480
}
Original file line number Diff line number Diff line change @@ -1234,6 +1234,12 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool {
1234
1234
}
1235
1235
accum
1236
1236
}
1237
+ ty_fn( fty) {
1238
+ alt fty. proto {
1239
+ proto_bare | proto_any | proto_block { false }
1240
+ _ { true }
1241
+ }
1242
+ }
1237
1243
_ { true }
1238
1244
} ;
1239
1245
Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ fn main(argv: [str]/~) {
22
22
#bench[ shift_push] ;
23
23
#bench[ read_line] ;
24
24
#bench[ str_set] ;
25
+ #bench[ vec_append] ;
26
+ #bench[ vec_push_all] ;
25
27
}
26
28
27
29
fn run_test ( name : str , test : fn ( ) ) {
@@ -72,3 +74,34 @@ fn str_set() {
72
74
}
73
75
}
74
76
}
77
+
78
+ fn vec_append ( ) {
79
+ let r = rand:: rng ( ) ;
80
+
81
+ let mut v = [ ] /~;
82
+ for uint:: range( 0 , 1500 ) { |i|
83
+ let rv = vec:: from_elem( r. gen_uint_range( 0 , i + 1 ) , i) ;
84
+ if r. gen_bool ( ) {
85
+ v += rv;
86
+ }
87
+ else {
88
+ v = rv + v;
89
+ }
90
+ }
91
+ }
92
+
93
+ fn vec_push_all( ) {
94
+ let r = rand:: rng ( ) ;
95
+
96
+ let mut v = [ ] /~;
97
+ for uint:: range( 0 , 1500 ) { |i|
98
+ let mut rv = vec:: from_elem( r. gen_uint_range( 0 , i + 1 ) , i) ;
99
+ if r. gen_bool( ) {
100
+ vec:: push_all( v, rv) ;
101
+ }
102
+ else {
103
+ v <-> rv;
104
+ vec:: push_all ( v , rv ) ;
105
+ }
106
+ }
107
+ }
You can’t perform that action at this time.
0 commit comments