You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by no...@apache.org on 2020/12/29 12:48:06 UTC
[buildstream] 13/16: _variables.pyx: Return to cpdef for
Variables.subst() and Variables.expand()
This is an automated email from the ASF dual-hosted git repository.
not-in-ldap pushed a commit to branch tristan/variables-refactor
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit d60ba68e777dbee021e11e9280235dc248247028
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Sat Jul 18 16:00:43 2020 +0900
_variables.pyx: Return to cpdef for Variables.subst() and Variables.expand()
Seems to add a slight calling overhead to separate these implementations
as cdef.
---
src/buildstream/_variables.pyx | 38 ++++++++++++--------------------------
1 file changed, 12 insertions(+), 26 deletions(-)
diff --git a/src/buildstream/_variables.pyx b/src/buildstream/_variables.pyx
index d6384f9..c4f86b6 100644
--- a/src/buildstream/_variables.pyx
+++ b/src/buildstream/_variables.pyx
@@ -180,7 +180,16 @@ cdef class Variables:
# a cyclic variable reference
#
cpdef expand(self, Node node):
- self._expand(node)
+ if isinstance(node, ScalarNode):
+ (<ScalarNode> node).value = self.subst(<ScalarNode> node)
+ elif isinstance(node, SequenceNode):
+ for entry in (<SequenceNode> node).value:
+ self.expand(entry)
+ elif isinstance(node, MappingNode):
+ for entry in (<MappingNode> node).value.values():
+ self.expand(entry)
+ else:
+ assert False, "Unknown 'Node' type"
# subst():
#
@@ -197,7 +206,8 @@ cdef class Variables:
# a cyclic variable reference
#
cpdef str subst(self, ScalarNode node):
- return self._subst(node)
+ value_expression = _parse_value_expression(node.as_str())
+ return self._expand_value_expression(value_expression)
#################################################################
# Private API #
@@ -224,30 +234,6 @@ cdef class Variables:
ret[sys.intern(key)] = _parse_value_expression(value)
return ret
- # _expand():
- #
- # Internal pure cython implementation of Variables.expand().
- #
- cdef _expand(self, Node node):
- if isinstance(node, ScalarNode):
- (<ScalarNode> node).value = self._subst(<ScalarNode> node)
- elif isinstance(node, SequenceNode):
- for entry in (<SequenceNode> node).value:
- self._expand(entry)
- elif isinstance(node, MappingNode):
- for entry in (<MappingNode> node).value.values():
- self._expand(entry)
- else:
- assert False, "Unknown 'Node' type"
-
- # _subst():
- #
- # Internal pure cython implementation of Variables.subst().
- #
- cdef str _subst(self, ScalarNode node):
- value_expression = _parse_value_expression(node.as_str())
- return self._expand_value_expression(value_expression)
-
# _check_variables()
#
# Raises a user facing error in the case that an error was detected