[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [arm/master] Caching tab completion match results



commit 3714ef4ed8b84029f2da11c639fdd9a64e8ddf1e
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Sep 19 07:52:27 2011 -0700

    Caching tab completion match results
    
    Thanks to the wonderfully weak pydoc explanations I'm kinda fuzzy on how the
    complete function is called, but this should reduce the number of extra prefix
    lookups that we do.
---
 src/util/torInterpretor.py |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/util/torInterpretor.py b/src/util/torInterpretor.py
index 658b65e..d5abb88 100644
--- a/src/util/torInterpretor.py
+++ b/src/util/torInterpretor.py
@@ -236,6 +236,9 @@ class TorControlCompleter:
   """
   
   def __init__(self):
+    self._prefix = None
+    self._prefixMatches = []
+    
     self.commands = []
     conn = torTools.getConn()
     
@@ -342,9 +345,13 @@ class TorControlCompleter:
     the readlines set_completer function.
     """
     
-    for cmd in self.getMatches(text):
-      if not state: return cmd
-      else: state -= 1
+    if text != self._prefix:
+      self._prefix = text
+      self._prefixMatches = self.getMatches(text)
+    
+    if state < len(self._prefixMatches):
+      return self._prefixMatches[state]
+    else: return None
 
 class ControlInterpretor:
   """



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits