summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <baker.dylan.c@gmail.com>2015-09-03 11:36:52 -0700
committerDylan Baker <baker.dylan.c@gmail.com>2015-09-22 14:45:49 -0700
commitae39cdd7baea1a3c5a4ccb4d4b675f47447599a0 (patch)
treeffe5d6190cdc3387322579cbf447980dac0b0099
parentb554800b3c7220dc17ca176ad0ac9d8c11c30475 (diff)
framework/status.py: Speed up status_lookup
This is a pretty hot function at this point, so making it faster is better. This works by pulling the dictionary that is used in place of a switch statement out of the function, and into the module. This presumably changes the lifetime of the dictionary making lookups faster. Signed-off-by: Dylan Baker <dylanx.c.baker@intel.com>
-rw-r--r--framework/status.py30
1 files changed, 15 insertions, 15 deletions
diff --git a/framework/status.py b/framework/status.py
index 28f8bfaa6..458cd84ac 100644
--- a/framework/status.py
+++ b/framework/status.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2013 Intel Corporation
+# Copyright (c) 2013, 2015 Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
@@ -85,21 +85,8 @@ def status_lookup(status):
if isinstance(status, Status):
return status
- status_dict = {
- 'skip': SKIP,
- 'pass': PASS,
- 'warn': WARN,
- 'fail': FAIL,
- 'crash': CRASH,
- 'dmesg-warn': DMESG_WARN,
- 'dmesg-fail': DMESG_FAIL,
- 'notrun': NOTRUN,
- 'timeout': TIMEOUT,
- 'incomplete': INCOMPLETE,
- }
-
try:
- return status_dict[status]
+ return _STATUS_MAP[status]
except KeyError:
# Raise a StatusException rather than a key error
raise StatusException(status)
@@ -252,6 +239,19 @@ CRASH = Status('crash', 60)
INCOMPLETE = Status('incomplete', 100)
+_STATUS_MAP = {
+ 'skip': SKIP,
+ 'pass': PASS,
+ 'warn': WARN,
+ 'fail': FAIL,
+ 'crash': CRASH,
+ 'dmesg-warn': DMESG_WARN,
+ 'dmesg-fail': DMESG_FAIL,
+ 'notrun': NOTRUN,
+ 'timeout': TIMEOUT,
+ 'incomplete': INCOMPLETE,
+}
+
# A tuple (ordered, immutable) of all statuses in this module
ALL = (PASS, WARN, DMESG_WARN, FAIL, DMESG_FAIL, TIMEOUT, CRASH, INCOMPLETE,
SKIP, NOTRUN)