@@ -362,12 +362,7 @@ where
362362 // Check if we need to replace head
363363 if self
364364 . read_data_in_node_at ( head)
365- . cmp ( self . read_data_in_node_at ( new) )
366- != K :: ordering ( )
367- {
368- self . node_at_mut ( new) . next = self . head ;
369- self . head = Idx :: new_unchecked ( new) ;
370- } else {
365+ . cmp ( self . read_data_in_node_at ( new) ) == K :: ordering ( ) {
371366 // It's not head, search the list for the correct placement
372367 let mut current = head;
373368
@@ -385,6 +380,9 @@ where
385380
386381 self . node_at_mut ( new) . next = self . node_at ( current) . next ;
387382 self . node_at_mut ( current) . next = Idx :: new_unchecked ( new) ;
383+ } else {
384+ self . node_at_mut ( new) . next = self . head ;
385+ self . head = Idx :: new_unchecked ( new) ;
388386 }
389387 } else {
390388 self . node_at_mut ( new) . next = self . head ;
@@ -416,11 +414,11 @@ where
416414 /// assert_eq!(ll.push(4), Err(4));
417415 /// ```
418416 pub fn push ( & mut self , value : T ) -> Result < ( ) , T > {
419- if !self . is_full ( ) {
417+ if self . is_full ( ) {
418+ Err ( value)
419+ } else {
420420 unsafe { self . push_unchecked ( value) }
421421 Ok ( ( ) )
422- } else {
423- Err ( value)
424422 }
425423 }
426424
@@ -571,10 +569,10 @@ where
571569 /// assert_eq!(ll.pop(), None);
572570 /// ```
573571 pub fn pop ( & mut self ) -> Option < T > {
574- if !self . is_empty ( ) {
575- Some ( unsafe { self . pop_unchecked ( ) } )
576- } else {
572+ if self . is_empty ( ) {
577573 None
574+ } else {
575+ Some ( unsafe { self . pop_unchecked ( ) } )
578576 }
579577 }
580578
0 commit comments