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:
parent
a8c1b2a463
commit
c2a772e797
@ -128,6 +128,9 @@ class Relation (object):
|
|||||||
'''
|
'''
|
||||||
newt = relation()
|
newt = relation()
|
||||||
newt.header = Header(self.header)
|
newt.header = Header(self.header)
|
||||||
|
|
||||||
|
c_expr = compile(expr, 'selection', 'eval')
|
||||||
|
|
||||||
for i in self.content:
|
for i in self.content:
|
||||||
# Fills the attributes dictionary with the values of the tuple
|
# Fills the attributes dictionary with the values of the tuple
|
||||||
attributes = {attr: i[j].autocast()
|
attributes = {attr: i[j].autocast()
|
||||||
@ -135,7 +138,7 @@ class Relation (object):
|
|||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if eval(expr, attributes):
|
if eval(c_expr, attributes):
|
||||||
newt.content.add(i)
|
newt.content.add(i)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
|
Loading…
Reference in New Issue
Block a user