@@ -101,10 +101,12 @@ fn link_with_prev<T>(mut next: ~Node<T>, prev: Rawlink<Node<T>>) -> Link<T> {
101
101
102
102
impl < T > Container for DList < T > {
103
103
/// O(1)
104
+ #[ inline]
104
105
fn is_empty ( & self ) -> bool {
105
106
self . list_head . is_none ( )
106
107
}
107
108
/// O(1)
109
+ #[ inline]
108
110
fn len ( & self ) -> uint {
109
111
self . length
110
112
}
@@ -114,39 +116,35 @@ impl<T> Mutable for DList<T> {
114
116
/// Remove all elements from the DList
115
117
///
116
118
/// O(N)
119
+ #[ inline]
117
120
fn clear ( & mut self ) {
118
121
* self = DList :: new ( )
119
122
}
120
123
}
121
124
122
125
impl < T > Deque < T > for DList < T > {
123
126
/// Provide a reference to the front element, or None if the list is empty
127
+ #[ inline]
124
128
fn front < ' a > ( & ' a self ) -> Option < & ' a T > {
125
- self . list_head . chain_ref ( |x| Some ( & x . value ) )
129
+ self . list_head . map ( |head| & head . value )
126
130
}
127
131
128
132
/// Provide a mutable reference to the front element, or None if the list is empty
133
+ #[ inline]
129
134
fn front_mut < ' a > ( & ' a mut self ) -> Option < & ' a mut T > {
130
- match self . list_head {
131
- None => None ,
132
- Some ( ref mut head) => Some ( & mut head. value ) ,
133
- }
135
+ self . list_head . map_mut ( |head| & mut head. value )
134
136
}
135
137
136
138
/// Provide a reference to the back element, or None if the list is empty
139
+ #[ inline]
137
140
fn back < ' a > ( & ' a self ) -> Option < & ' a T > {
138
- match self . list_tail . resolve_immut ( ) {
139
- None => None ,
140
- Some ( tail) => Some ( & tail. value ) ,
141
- }
141
+ self . list_tail . resolve_immut ( ) . map ( |tail| & tail. value )
142
142
}
143
143
144
144
/// Provide a mutable reference to the back element, or None if the list is empty
145
+ #[ inline]
145
146
fn back_mut < ' a > ( & ' a mut self ) -> Option < & ' a mut T > {
146
- match self . list_tail . resolve ( ) {
147
- None => None ,
148
- Some ( tail) => Some ( & mut tail. value ) ,
149
- }
147
+ self . list_tail . resolve ( ) . map_mut ( |tail| & mut tail. value )
150
148
}
151
149
152
150
/// Add an element last in the list
@@ -167,7 +165,6 @@ impl<T> Deque<T> for DList<T> {
167
165
/// Remove the last element and return it, or None if the list is empty
168
166
///
169
167
/// O(1)
170
- #[ inline]
171
168
fn pop_back ( & mut self ) -> Option < T > {
172
169
match self . list_tail . resolve ( ) {
173
170
None => None ,
@@ -259,6 +256,7 @@ impl<T> DList<T> {
259
256
/// Add all elements from `other` to the beginning of the list
260
257
///
261
258
/// O(1)
259
+ #[ inline]
262
260
pub fn prepend ( & mut self , mut other : DList < T > ) {
263
261
util:: swap ( self , & mut other) ;
264
262
self . append ( other) ;
@@ -268,7 +266,6 @@ impl<T> DList<T> {
268
266
/// or at the end.
269
267
///
270
268
/// O(N)
271
- #[ inline]
272
269
pub fn insert_when ( & mut self , elt : T , f : & fn ( & T , & T ) -> bool ) {
273
270
{
274
271
let mut it = self . mut_iter ( ) ;
@@ -309,16 +306,19 @@ impl<T> DList<T> {
309
306
310
307
311
308
/// Provide a forward iterator
309
+ #[ inline]
312
310
pub fn iter < ' a > ( & ' a self ) -> DListIterator < ' a , T > {
313
311
DListIterator { nelem : self . len ( ) , head : & self . list_head , tail : self . list_tail }
314
312
}
315
313
316
314
/// Provide a reverse iterator
315
+ #[ inline]
317
316
pub fn rev_iter < ' a > ( & ' a self ) -> InvertIterator < & ' a T , DListIterator < ' a , T > > {
318
317
self . iter ( ) . invert ( )
319
318
}
320
319
321
320
/// Provide a forward iterator with mutable references
321
+ #[ inline]
322
322
pub fn mut_iter < ' a > ( & ' a mut self ) -> MutDListIterator < ' a , T > {
323
323
let head_raw = match self . list_head {
324
324
Some ( ref mut h) => Rawlink :: some ( * h) ,
@@ -332,18 +332,21 @@ impl<T> DList<T> {
332
332
}
333
333
}
334
334
/// Provide a reverse iterator with mutable references
335
+ #[ inline]
335
336
pub fn mut_rev_iter < ' a > ( & ' a mut self ) -> InvertIterator < & ' a mut T ,
336
337
MutDListIterator < ' a , T > > {
337
338
self . mut_iter ( ) . invert ( )
338
339
}
339
340
340
341
341
342
/// Consume the list into an iterator yielding elements by value
343
+ #[ inline]
342
344
pub fn consume_iter ( self ) -> ConsumeIterator < T > {
343
345
ConsumeIterator { list : self }
344
346
}
345
347
346
348
/// Consume the list into an iterator yielding elements by value, in reverse
349
+ #[ inline]
347
350
pub fn consume_rev_iter ( self ) -> InvertIterator < T , ConsumeIterator < T > > {
348
351
self . consume_iter ( ) . invert ( )
349
352
}
@@ -353,6 +356,7 @@ impl<T: cmp::TotalOrd> DList<T> {
353
356
/// Insert `elt` sorted in ascending order
354
357
///
355
358
/// O(N)
359
+ #[ inline]
356
360
pub fn insert_ordered ( & mut self , elt : T ) {
357
361
self . insert_when ( elt, |a, b| a. cmp ( b) != cmp:: Less ) ;
358
362
}
@@ -374,12 +378,14 @@ impl<'self, A> Iterator<&'self A> for DListIterator<'self, A> {
374
378
}
375
379
}
376
380
381
+ #[ inline]
377
382
fn size_hint ( & self ) -> ( uint , Option < uint > ) {
378
383
( self . nelem , Some ( self . nelem ) )
379
384
}
380
385
}
381
386
382
387
impl < ' self , A > DoubleEndedIterator < & ' self A > for DListIterator < ' self , A > {
388
+ #[ inline]
383
389
fn next_back ( & mut self ) -> Option < & ' self A > {
384
390
if self . nelem == 0 {
385
391
return None ;
@@ -414,6 +420,7 @@ impl<'self, A> Iterator<&'self mut A> for MutDListIterator<'self, A> {
414
420
}
415
421
}
416
422
423
+ #[ inline]
417
424
fn size_hint ( & self ) -> ( uint , Option < uint > ) {
418
425
( self . nelem , Some ( self . nelem ) )
419
426
}
@@ -466,6 +473,7 @@ impl<'self, A> ListInsertion<A> for MutDListIterator<'self, A> {
466
473
}
467
474
}
468
475
476
+ #[ inline]
469
477
fn peek_next < ' a > ( & ' a mut self ) -> Option < & ' a mut A > {
470
478
match self . head . resolve ( ) {
471
479
None => None ,
@@ -475,13 +483,17 @@ impl<'self, A> ListInsertion<A> for MutDListIterator<'self, A> {
475
483
}
476
484
477
485
impl < A > Iterator < A > for ConsumeIterator < A > {
486
+ #[ inline]
478
487
fn next ( & mut self ) -> Option < A > { self . list . pop_front ( ) }
488
+
489
+ #[ inline]
479
490
fn size_hint ( & self ) -> ( uint , Option < uint > ) {
480
491
( self . list . length , Some ( self . list . length ) )
481
492
}
482
493
}
483
494
484
495
impl < A > DoubleEndedIterator < A > for ConsumeIterator < A > {
496
+ #[ inline]
485
497
fn next_back ( & mut self ) -> Option < A > { self . list . pop_back ( ) }
486
498
}
487
499
@@ -498,6 +510,8 @@ impl<A: Eq> Eq for DList<A> {
498
510
self . len ( ) == other. len ( ) &&
499
511
self . iter ( ) . zip ( other. iter ( ) ) . all ( |( a, b) | a. eq ( b) )
500
512
}
513
+
514
+ #[ inline]
501
515
fn ne ( & self , other : & DList < A > ) -> bool {
502
516
!self . eq ( other)
503
517
}
0 commit comments