@@ -38,40 +38,46 @@ private bool IsLastAccessedValid()
3838
3939 private LinkedListNode < string > GetNodeAt ( int index )
4040 {
41+ LinkedListNode < string > nodeAtIndex ;
4142 if ( index == 0 )
4243 {
43- return lines . First ;
44+ nodeAtIndex = lines . First ;
4445 }
45-
46- if ( index == Count - 1 )
46+ else if ( index == Count - 1 )
4747 {
48- return lines . Last ;
48+ nodeAtIndex = lines . Last ;
4949 }
50-
51- LinkedListNode < string > node ;
52- int searchDirection ;
53- int count ;
54- GetClosestReference ( index , out node , out count , out searchDirection ) ;
55- while ( node != null )
50+ else
5651 {
57- if ( count == index )
52+ int searchDirection ;
53+ int count ;
54+ GetClosestReference ( index , out nodeAtIndex , out count , out searchDirection ) ;
55+ while ( nodeAtIndex != null )
5856 {
59- SetLastAccessed ( index , node ) ;
60- return node ;
57+ if ( count == index )
58+ {
59+ break ;
60+ }
61+
62+ count += searchDirection ;
63+ if ( searchDirection > 0 )
64+ {
65+ nodeAtIndex = nodeAtIndex . Next ;
66+ }
67+ else
68+ {
69+ nodeAtIndex = nodeAtIndex . Previous ;
70+ }
6171 }
6272
63- count += searchDirection ;
64- if ( searchDirection > 0 )
65- {
66- node = node . Next ;
67- }
68- else
73+ if ( nodeAtIndex == null )
6974 {
70- node = node . Previous ;
75+ throw new InvalidOperationException ( ) ;
7176 }
7277 }
7378
74- throw new InvalidOperationException ( ) ;
79+ SetLastAccessed ( index , nodeAtIndex ) ;
80+ return nodeAtIndex ;
7581 }
7682
7783 private void GetClosestReference (
0 commit comments