summaryrefslogtreecommitdiff
path: root/trove/quota
diff options
context:
space:
mode:
authorChangBo Guo(gcb) <eric.guo@easystack.cn>2014-12-24 23:05:48 +0800
committerChangBo Guo(gcb) <eric.guo@easystack.cn>2015-01-09 22:36:37 +0800
commit0ee91a5854830736c8e6ea5d140bcf3ce965fa3c (patch)
tree6008b0b8c85e943c1e7bcfe08c362abb62bde90a /trove/quota
parentf86a0e6cc283cd786d244b394892ced8bc32eeaa (diff)
downloadtrove-0ee91a5854830736c8e6ea5d140bcf3ce965fa3c.tar.gz
Use dict comprehensions instead of dict constructor
PEP-0274 introduced dict comprehensions to replace dict constructor with a sequence of key-value pair, these are benefits copied from [1]: The dictionary constructor approach has two distinct disadvantages from the proposed syntax though. First, it isn't as legible as a dict comprehension. Second, it forces the programmer to create an in-core list object first, which could be expensive. There is deep dive about PEP-0274[2] and basic tests about performance[3]. Note: This commit doesn't handle dict constructor with kwagrs. [1]http://legacy.python.org/dev/peps/pep-0274/ [2]http://doughellmann.com/2012/11/12/the-performance-impact-of-using-dict-instead-of-in-cpython-2-7-2.html [3]http://paste.openstack.org/show/154798/ Change-Id: I45d0c289ecaf63a343fc9ad935cf2893d67d938a
Diffstat (limited to 'trove/quota')
-rw-r--r--trove/quota/quota.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/trove/quota/quota.py b/trove/quota/quota.py
index 3fc1ac66..8dc44427 100644
--- a/trove/quota/quota.py
+++ b/trove/quota/quota.py
@@ -58,9 +58,8 @@ class DbQuotaDriver(object):
"""
all_quotas = Quota.find_all(tenant_id=tenant_id).all()
- result_quotas = dict((quota.resource, quota)
- for quota in all_quotas
- if quota.resource in resources)
+ result_quotas = {quota.resource: quota for quota in all_quotas
+ if quota.resource in resources}
if len(result_quotas) != len(resources):
for resource in resources:
@@ -94,9 +93,8 @@ class DbQuotaDriver(object):
"""
all_usages = QuotaUsage.find_all(tenant_id=tenant_id).all()
- result_usages = dict((usage.resource, usage)
- for usage in all_usages
- if usage.resource in resources)
+ result_usages = {usage.resource: usage for usage in all_usages
+ if usage.resource in resources}
if len(result_usages) != len(resources):
for resource in resources:
# Not in the DB, return default value