summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-01-21 03:58:24 +0100
committerhut <hut@lavabit.com>2010-01-21 04:00:10 +0100
commit9d9687a63e1e07828f788c943b775185dac995f6 (patch)
tree61a85cf57f6be11cdee131713ac289912b986229
parentb953eb51ab4f70f35e643a6b345a79b98d9cea98 (diff)
downloadranger-9d9687a63e1e07828f788c943b775185dac995f6.tar.gz
commands: use deque in find command
-rw-r--r--ranger/commands.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/ranger/commands.py b/ranger/commands.py
index a3137ddb..a1c2f028 100644
--- a/ranger/commands.py
+++ b/ranger/commands.py
@@ -13,6 +13,7 @@
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 import os
+from collections import deque
 from ranger.shared import FileManagerAware
 from ranger.gui.widgets import console_mode as cmode
 from ranger.ext.command_parser import LazyParser as parse
@@ -215,17 +216,19 @@ class find(Command):
 		except IndexError:
 			return False
 		
-		length = len(pwd.files)
-		for i in range(length):
-			actual_index = (pwd.pointer + i) % length
-			filename = pwd.files[actual_index].basename_lower
+		deq = deque(pwd.files)
+		deq.rotate(-pwd.pointer)
+		i = 0
+		for fsobj in deq:
+			filename = fsobj.basename_lower
 			if arg in filename:
 				self.count += 1
 				if self.count == 1:
-					pwd.move(absolute=actual_index)
+					pwd.move(absolute=(pwd.pointer + i) % len(pwd.files))
 					self.fm.env.cf = pwd.pointed_obj
 			if self.count > 1:
 				return False
+			i += 1
 
 		return self.count == 1