File tree Expand file tree Collapse file tree 1 file changed +5
-8
lines changed
Expand file tree Collapse file tree 1 file changed +5
-8
lines changed Original file line number Diff line number Diff line change @@ -98,14 +98,11 @@ impl History {
9898 match end_point {
9999 EndPoint :: CommandNumber ( n) => {
100100 if let Some ( first) = self . entries . front ( ) {
101- if n <= first. command_number {
102- // we wrapped around, look for the command from the back
103- // TODO: I think this can be done in constant time
104- Ok ( self
105- . entries
106- . iter ( )
107- . rposition ( |e| e. command_number == n)
108- . unwrap_or ( self . entries . len ( ) - 1 ) )
101+ if n < first. command_number {
102+ // safe since there is at least one element
103+ let last_command_number = self . entries . back ( ) . unwrap ( ) . command_number ;
104+ let commands_in_between = ( last_command_number - n) as usize ;
105+ Ok ( self . entries . len ( ) - commands_in_between - 1 )
109106 } else {
110107 Ok ( ( n - first. command_number ) as usize )
111108 }
You can’t perform that action at this time.
0 commit comments