Although minor, you could move exp.OutputPorts.Count a little earlier in your code as it’s testing the same thing for each input port on the operator. You should only have to test that once per expression, like this:
def getExpressionsDrivenByParameter( param ):
allExpressions = xsi.FindObjects(None, "{12723EB2-7DDB-11D0-A57F-00A0C91412DE}")
result = []
for exp in allExpressions:
if exp.OutputPorts.Count:
for port in exp.InputPorts:
if port.Target2.IsEqualTo(param):
result.append(exp)
break
return result
Other than that, you’re dealing with an O(n^2) runtime. The only way to make it significantly faster is to unroll the loops, but may not be possible for this task. You could try reading the “target” and “definition” parameters of the expression, but those may be ambiguous for some cases and also result in string comparisons which may or may not be faster.
Matt
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2012.0.2197 / Virus Database: 2437/5158 - Release Date: 07/27/12
import xml.etree.ElementTree as ET def getExpressionsDrivenByParameter( param ): stack = XSIUtils.DataRepository.GetConnectionStackInfo(param) expressions = XSIFactory.CreateObject('XSI.Collection') xml = ET.fromstring(stack) for conn in xml.findall('connection'): if conn.find('type').text == 'out': item = conn.find('object').text if item.endswith('.Expression'): expressions.AddItems(item) return expressions
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2012.0.2197 / Virus Database: 2437/5162 - Release Date: 07/29/12