Compile selection expression

When running a selection, compiling the expression into a code object
so that it does not need to be re-parsed per every iteration.

Since it saves one parse per iteration, the gains become more
noticeable as the size of the relations grow.
This commit is contained in:
Salvo 'LtWorf' Tomaselli 2015-11-20 15:48:20 +01:00
parent a8c1b2a463
commit c2a772e797

View File

@ -128,6 +128,9 @@ class Relation (object):
'''
newt = relation()
newt.header = Header(self.header)
c_expr = compile(expr, 'selection', 'eval')
for i in self.content:
# Fills the attributes dictionary with the values of the tuple
attributes = {attr: i[j].autocast()
@ -135,7 +138,7 @@ class Relation (object):
}
try:
if eval(expr, attributes):
if eval(c_expr, attributes):
newt.content.add(i)
except Exception as e:
raise Exception(