Commits

Evgeny Podjachev committed c8882e1 Merge

Minor.

  • Participants
  • Parent commits 36c7345, b036310

Comments (0)

Files changed (2)

plugin/fastfileselector.vim

 " 				search string. Autocompletion using history also works by
 " 				<Ctrl-X><Ctrl-U>.
 "
-" Version:		0.1.0
+" Version:		0.2.1
 "
-" ChangeLog:	0.2.0: Added support of GetLatestVimScripts.
+" ChangeLog:	0.2.1: Bug fixes and optimization of search.
 "
-"				0.1.0:	 Initial version.
+" 				0.2.0: Added support of GetLatestVimScripts.
+"
+"				0.1.0: Initial version.
 "
 " GetLatestVimScripts: 4142 18299 :AutoInstall: fastfileselector.vim
 "====================================================================================
 
 	fileList = []
 	for root, dirs, files in walk(path):
-		fileList += [join(root, f) for f in filter(lambda x: not in_ignore_list(x), files)]
+		fileList += [join(root, f) for f in files if not in_ignore_list(f)]
 
 		toRemove = filter(in_ignore_list, dirs)
 		for j in toRemove:

tests/benchmark.py

 import time
 
+import os
 from os import walk, getcwdu
-from os.path import join
+from os.path import join, getctime, getmtime, exists
 from fnmatch import fnmatch
 import operator
 
+import sqlite3
+
 if 1:
 	import string
 	caseMod = string.lower
 else:
 	caseMod = lambda x: x
 
-def scan_dir(path, ignoreList):
+class PathsCache(object):
+	def __init__(self, pathToCache, caseSensitivePaths):
+		self.caseSensitivePaths = caseSensitivePaths
+
+		# Check if database file exists and creates all needed paths.
+		createTable = False
+		if not exists(pathToCache):
+			createTable = True
+			try:
+				os.makedirs(os.path.split(pathToCache)[0])
+			except OSError:
+				pass
+
+		self.conn = None
+		with sqlite3.connect(pathToCache) as conn:
+			self.conn = conn
+			if createTable:
+				c = conn.cursor()
+				c.executescript("""
+					CREATE TABLE roots (id INTEGER PRIMARY KEY AUTOINCREMENT, path TEXT);
+					CREATE TABLE paths (id INTEGER PRIMARY KEY AUTOINCREMENT, root_id INTEGER SECONDARY KEY, parent INTEGER SECONDARY KEY, path TEXT, modtime INTEGER);
+				""")
+				conn.commit()
+				c.close()
+
+	def getCachedPaths(self, path):
+		if self.conn == None:
+			return []
+
+		if self.caseSensitivePaths:
+			addon = ''
+		else:
+			addon = 'COLLATE NOCASE'
+
+		c = self.conn.cursor()
+
+		# get parent id
+		c.execute('SELECT id FROM paths WHERE path = "%s" %s' % (path, addon))
+		c.close()
+
+		return []
+
+	def updateCachedPaths(self, root, paths):
+		if self.conn == None:
+			return
+
+		if self.caseSensitivePaths:
+			addon = ''
+		else:
+			addon = 'COLLATE NOCASE'
+
+		c = self.conn.cursor()
+
+		# get root id
+		c.execute('SELECT id FROM paths WHERE path = "%s" %s' % (root, addon))
+
+
+		c.execute("INSERT OR REPLACE INTO paths VALUES
+
+		self.conn.commit()
+		c.close()
+
+def scan_dir(path, ignoreList, cache_provider):
 	ignoreList = map(caseMod, ignoreList)
 	def in_ignore_list(f):
 		for i in ignoreList:
 
 	fileList = []
 	for root, dirs, files in walk(path):
-		fileList += [join(root, f) for f in filter(lambda x: not in_ignore_list(x), files)]
+		fileList += [join(root, f) for f in files if not in_ignore_list(f)]
 		
 		toRemove = filter(in_ignore_list, dirs)
 		for j in toRemove:
 			dirs.remove(j)
 
 	n = len(path.encode("utf-8"))
+
 	fileList = map(lambda x: x.encode("utf-8"), fileList)
 	fileList = map(lambda x: (caseMod(x[n:]), x), fileList)
 
 	ignore_list = ['.*', '*.bak', '~*', '*.obj', '*.pdb', '*.res', '*.dll', '*.idb', '*.exe', '*.lib', '*.so']
 	filter_string = caseMod('root')
 
-#	timing(scan_dir, 5, {'path' : path, 'ignoreList' : ignore_list})
+#	timing(scan_dir, 2, {'path' : path, 'ignoreList' : ignore_list})
 	
 	file_list = scan_dir(path, ignore_list)
 
 		fileList = filter(operator.itemgetter(0), fileList)
 		fileList.sort(key=operator.itemgetter(0, 1))
 
-	timing(filterFileList, 5, {'fileList':file_list})
+	#timing(filterFileList, 5, {'fileList':file_list})
 
+	init_cache('K:/home_projects/fastfileselector/tests/db.db')