Skip to content

Commit b61a0ea

Browse files
committed
src/sage/interfaces/maxima_abstract.py: micro-optimize _commands()
The _commands() method checks the first character of each command to make sure that it starts with a letter. This _was_ searching a tuple (containing 'a' to 'Z'), but it seems to be much faster if we concatenate them all into one string and search that instead.
1 parent 903c60e commit b61a0ea

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/sage/interfaces/maxima_abstract.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,12 @@ def _commands(self):
319319
# Passing the empty string to apropos() gets ALL names.
320320
all_names = self._eval_line('apropos("")',
321321
error_check=False).split(",")
322-
a_to_Z = tuple(chr(i+j)
323-
for i in range(ord('A'),ord('Z')+1)
324-
for j in (0, 32)) # 'a' = 'A' + 32
322+
323+
# At the time of writing, searching a string for a specific
324+
# character was much much faster than searching a list/tuple.
325+
a_to_Z = "".join(chr(i+j)
326+
for i in range(ord('A'),ord('Z')+1)
327+
for j in (0, 32)) # 'a' = 'A' + 32
325328

326329
# Whack-a-mole to kill junk entries:
327330
#

0 commit comments

Comments
 (0)