about summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-02-26 01:44:25 +0100
committerhut <hut@lavabit.com>2010-02-27 04:39:54 +0100
commit6d985a2c49ce554cefc8d2259fc5a61e4be5f94e (patch)
tree0356ebf6a49947ca360f4aa12f3739bf030f05db /ranger
parent24cd97b78d90b3b7311381d1c4bab7160d14604f (diff)
downloadranger-6d985a2c49ce554cefc8d2259fc5a61e4be5f94e.tar.gz
colorscheme: slight performance increase
Diffstat (limited to 'ranger')
-rw-r--r--ranger/ext/openstruct.py4
-rw-r--r--ranger/gui/colorscheme.py15
2 files changed, 10 insertions, 9 deletions
diff --git a/ranger/ext/openstruct.py b/ranger/ext/openstruct.py
index bf471605..2e8663f0 100644
--- a/ranger/ext/openstruct.py
+++ b/ranger/ext/openstruct.py
@@ -28,3 +28,7 @@ class OpenStruct(object):
 
 	def __contains__(self, key):
 		return key in self.__dict__
+
+class ReferencedOpenStruct(OpenStruct):
+	def __init__(self, dictionary):
+		self.__dict__ = dictionary
diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py
index 9abc0486..0fdfbd65 100644
--- a/ranger/gui/colorscheme.py
+++ b/ranger/gui/colorscheme.py
@@ -40,7 +40,9 @@ If your colorscheme-file contains more than one colorscheme, specify it with:
 colorscheme = colorschemes.filename.classname
 """
 
-from ranger.ext.openstruct import OpenStruct
+from ranger.ext.openstruct import ReferencedOpenStruct
+from curses import color_pair
+from ranger.gui.color import get_color
 
 CONTEXT_KEYS = ['reset', 'error',
 		'in_browser', 'in_statusbar', 'in_titlebar', 'in_console',
@@ -77,14 +79,13 @@ class ColorScheme(object):
 		Using this function rather than use() will cache all
 		colors for faster access.
 		"""
+		keys = frozenset(keys)
 		try:
 			return self.cache[keys]
 
 		except KeyError:
-			context = OpenStruct()
-
-			for key in CONTEXT_KEYS:
-				context[key] = (key in keys)
+			context = ReferencedOpenStruct(dict(
+				(key, key in keys) for key in CONTEXT_KEYS))
 
 			# add custom error messages for broken colorschemes
 			color = self.use(context)
@@ -97,9 +98,6 @@ class ColorScheme(object):
 
 		Ready to use for curses.setattr()
 		"""
-		from curses import color_pair
-		from ranger.gui.color import get_color
-
 		fg, bg, attr = self.get(*keys)
 		return attr | color_pair(get_color(fg, bg))
 
@@ -110,5 +108,4 @@ class ColorScheme(object):
 		Override this in your custom colorscheme!
 		"""
 		from ranger.gui.color import default_colors
-
 		return default_colors