summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTravis Scrimshaw <tscrimsh at umn.edu>2016-01-02 03:15:59 -0600
committerTravis Scrimshaw <tscrimsh at umn.edu>2016-01-02 03:15:59 -0600
commit0b5fcec3ea079b5240414f4981bd860d7768b3c7 (patch)
treeb07bb83842a72a12441b19dcc4ddabb43df581ae
parentAdded length cache to quantum_bruhat_graph(). (diff)
Get a little more speed by using the matrices as keys for the length cache.
-rw-r--r--src/sage/categories/weyl_groups.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/sage/categories/weyl_groups.py b/src/sage/categories/weyl_groups.py
index 06faa20..ba953c0 100644
--- a/src/sage/categories/weyl_groups.py
+++ b/src/sage/categories/weyl_groups.py
@@ -182,10 +182,12 @@ class WeylGroups(Category_singleton):
# relatively expensive to compute and needed frequently
len_cache = {}
def length(x):
- if x in len_cache:
- return len_cache[x]
- len_cache[x] = x.length()
- return len_cache[x]
+ # It is sufficient and faster to use the matrices as the keys
+ m = x.matrix()
+ if m in len_cache:
+ return len_cache[m]
+ len_cache[m] = x.length()
+ return len_cache[m]
def succ(x):
w_length_plus_one = length(x) + 1
successors = []