summary refs log tree commit diff stats
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
parent24cd97b78d90b3b7311381d1c4bab7160d14604f (diff)
downloadranger-6d985a2c49ce554cefc8d2259fc5a61e4be5f94e.tar.gz
colorscheme: slight performance increase
-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
207'>207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461