@@ -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,28 +116,33 @@ 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
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
135
self . list_head . map_mut ( |head| & mut head. value )
131
136
}
132
137
133
138
/// Provide a reference to the back element, or None if the list is empty
139
+ #[ inline]
134
140
fn back < ' a > ( & ' a self ) -> Option < & ' a T > {
135
141
self . list_tail . resolve_immut ( ) . map ( |tail| & tail. value )
136
142
}
137
143
138
144
/// Provide a mutable reference to the back element, or None if the list is empty
145
+ #[ inline]
139
146
fn back_mut < ' a > ( & ' a mut self ) -> Option < & ' a mut T > {
140
147
self . list_tail . resolve ( ) . map_mut ( |tail| & mut tail. value )
141
148
}
@@ -158,7 +165,6 @@ impl<T> Deque<T> for DList<T> {
158
165
/// Remove the last element and return it, or None if the list is empty
159
166
///
160
167
/// O(1)
161
- #[ inline]
162
168
fn pop_back ( & mut self ) -> Option < T > {
163
169
match self . list_tail . resolve ( ) {
164
170
None => None ,
@@ -250,6 +256,7 @@ impl<T> DList<T> {
250
256
/// Add all elements from `other` to the beginning of the list
251
257
///
252
258
/// O(1)
259
+ #[ inline]
253
260
pub fn prepend ( & mut self , mut other : DList < T > ) {
254
261
util:: swap ( self , & mut other) ;
255
262
self . append ( other) ;
@@ -259,7 +266,6 @@ impl<T> DList<T> {
259
266
/// or at the end.
260
267
///
261
268
/// O(N)
262
- #[ inline]
263
269
pub fn insert_when ( & mut self , elt : T , f : & fn ( & T , & T ) -> bool ) {
264
270
{
265
271
let mut it = self . mut_iter ( ) ;
@@ -300,16 +306,19 @@ impl<T> DList<T> {
300
306
301
307
302
308
/// Provide a forward iterator
309
+ #[ inline]
303
310
pub fn iter < ' a > ( & ' a self ) -> DListIterator < ' a , T > {
304
311
DListIterator { nelem : self . len ( ) , head : & self . list_head , tail : self . list_tail }
305
312
}
306
313
307
314
/// Provide a reverse iterator
315
+ #[ inline]
308
316
pub fn rev_iter < ' a > ( & ' a self ) -> InvertIterator < & ' a T , DListIterator < ' a , T > > {
309
317
self . iter ( ) . invert ( )
310
318
}
311
319
312
320
/// Provide a forward iterator with mutable references
321
+ #[ inline]
313
322
pub fn mut_iter < ' a > ( & ' a mut self ) -> MutDListIterator < ' a , T > {
314
323
let head_raw = match self . list_head {
315
324
Some ( ref mut h) => Rawlink :: some ( * h) ,
@@ -323,18 +332,21 @@ impl<T> DList<T> {
323
332
}
324
333
}
325
334
/// Provide a reverse iterator with mutable references
335
+ #[ inline]
326
336
pub fn mut_rev_iter < ' a > ( & ' a mut self ) -> InvertIterator < & ' a mut T ,
327
337
MutDListIterator < ' a , T > > {
328
338
self . mut_iter ( ) . invert ( )
329
339
}
330
340
331
341
332
342
/// Consume the list into an iterator yielding elements by value
343
+ #[ inline]
333
344
pub fn consume_iter ( self ) -> ConsumeIterator < T > {
334
345
ConsumeIterator { list : self }
335
346
}
336
347
337
348
/// Consume the list into an iterator yielding elements by value, in reverse
349
+ #[ inline]
338
350
pub fn consume_rev_iter ( self ) -> InvertIterator < T , ConsumeIterator < T > > {
339
351
self . consume_iter ( ) . invert ( )
340
352
}
@@ -344,6 +356,7 @@ impl<T: cmp::TotalOrd> DList<T> {
344
356
/// Insert `elt` sorted in ascending order
345
357
///
346
358
/// O(N)
359
+ #[ inline]
347
360
pub fn insert_ordered ( & mut self , elt : T ) {
348
361
self . insert_when ( elt, |a, b| a. cmp ( b) != cmp:: Less ) ;
349
362
}
@@ -365,12 +378,14 @@ impl<'self, A> Iterator<&'self A> for DListIterator<'self, A> {
365
378
}
366
379
}
367
380
381
+ #[ inline]
368
382
fn size_hint ( & self ) -> ( uint , Option < uint > ) {
369
383
( self . nelem , Some ( self . nelem ) )
370
384
}
371
385
}
372
386
373
387
impl < ' self , A > DoubleEndedIterator < & ' self A > for DListIterator < ' self , A > {
388
+ #[ inline]
374
389
fn next_back ( & mut self ) -> Option < & ' self A > {
375
390
if self . nelem == 0 {
376
391
return None ;
@@ -405,6 +420,7 @@ impl<'self, A> Iterator<&'self mut A> for MutDListIterator<'self, A> {
405
420
}
406
421
}
407
422
423
+ #[ inline]
408
424
fn size_hint ( & self ) -> ( uint , Option < uint > ) {
409
425
( self . nelem , Some ( self . nelem ) )
410
426
}
@@ -457,6 +473,7 @@ impl<'self, A> ListInsertion<A> for MutDListIterator<'self, A> {
457
473
}
458
474
}
459
475
476
+ #[ inline]
460
477
fn peek_next < ' a > ( & ' a mut self ) -> Option < & ' a mut A > {
461
478
match self . head . resolve ( ) {
462
479
None => None ,
@@ -466,13 +483,17 @@ impl<'self, A> ListInsertion<A> for MutDListIterator<'self, A> {
466
483
}
467
484
468
485
impl < A > Iterator < A > for ConsumeIterator < A > {
486
+ #[ inline]
469
487
fn next ( & mut self ) -> Option < A > { self . list . pop_front ( ) }
488
+
489
+ #[ inline]
470
490
fn size_hint ( & self ) -> ( uint , Option < uint > ) {
471
491
( self . list . length , Some ( self . list . length ) )
472
492
}
473
493
}
474
494
475
495
impl < A > DoubleEndedIterator < A > for ConsumeIterator < A > {
496
+ #[ inline]
476
497
fn next_back ( & mut self ) -> Option < A > { self . list . pop_back ( ) }
477
498
}
478
499
@@ -489,6 +510,8 @@ impl<A: Eq> Eq for DList<A> {
489
510
self . len ( ) == other. len ( ) &&
490
511
self . iter ( ) . zip ( other. iter ( ) ) . all ( |( a, b) | a. eq ( b) )
491
512
}
513
+
514
+ #[ inline]
492
515
fn ne ( & self , other : & DList < A > ) -> bool {
493
516
!self . eq ( other)
494
517
}
0 commit comments