sdbus++: method: reduce mako embedded python

Embedded Python in the Mako templates is slower than native Python.
Promote some of the functions in the Mako templates to real member
functions in the `Method` class.

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I06e16e840cfdbe7a87889269d2de8602b9a9bfc4
diff --git a/tools/sdbusplus/method.py b/tools/sdbusplus/method.py
index 726355e..bb8460c 100644
--- a/tools/sdbusplus/method.py
+++ b/tools/sdbusplus/method.py
@@ -39,18 +39,31 @@
         else:
             return "std::tuple<" + self.returns_as_list(interface) + ">"
 
-    def parameter(self, interface, p, defaultValue=False):
-        r = "%s %s" % (p.cppTypeParam(interface.name), p.camelCase)
+    def parameter(self, interface, p, defaultValue=False, ref=""):
+        r = "%s%s %s" % (p.cppTypeParam(interface.name), ref, p.camelCase)
         if defaultValue:
             r += p.default_value()
         return r
 
+    def parameters_as_list(
+        self, transform=lambda p: p.camelCase, join_str=", "
+    ):
+        return join_str.join([transform(p) for p in self.parameters])
+
+    def parameters_as_arg_list(self, interface):
+        return self.parameters_as_list(
+            lambda p: self.parameter(interface, p, ref="&&")
+        )
+
+    def parameter_types_as_list(self, interface):
+        return self.parameters_as_list(
+            lambda p: p.cppTypeParam(interface.name, full=True)
+        )
+
     def get_parameters_str(self, interface, defaultValue=False):
-        return ",\n            ".join(
-            [
-                self.parameter(interface, p, defaultValue)
-                for p in self.parameters
-            ]
+        return self.parameters_as_list(
+            lambda p: self.parameter(interface, p, defaultValue),
+            ",\n            ",
         )
 
     def or_cpp_flags(self, flags):
diff --git a/tools/sdbusplus/templates/method.prototype.hpp.mako b/tools/sdbusplus/templates/method.prototype.hpp.mako
index 9c6b89c..f86458a 100644
--- a/tools/sdbusplus/templates/method.prototype.hpp.mako
+++ b/tools/sdbusplus/templates/method.prototype.hpp.mako
@@ -1,26 +1,4 @@
 <%
-    def parameters_as_arg_list():
-        return ", ".join([ parameter(p, ref="&&") for p in method.parameters ])
-
-    def parameters_as_list(transform=lambda p: p.camelCase):
-        return ", ".join([ transform(p) for p in method.parameters ])
-
-    def parameters_types_as_list():
-        return ", ".join([ p.cppTypeParam(interface.name, full=True)
-                for p in method.parameters ])
-
-    def parameter(p, defaultValue=False, ref=""):
-        r = "%s%s %s" % (p.cppTypeParam(interface.name), ref, p.camelCase)
-        if defaultValue:
-            r += default_value(p)
-        return r
-
-    def default_value(p):
-        if p.defaultValue != None:
-            return " = " + str(p.defaultValue)
-        else:
-            return ""
-
     def interface_name():
         return interface.name.split('.').pop()
 
@@ -104,10 +82,10 @@
 (
                 msg, o->_intf, error,
                 std::function(
-                    [=](${parameters_as_arg_list()})
+                    [=](${method.parameters_as_arg_list(interface)})
                     {
                         return o->${ method.camelCase }(
-                                ${parameters_as_list()});
+                                ${method.parameters_as_list()});
                     }
                 ));
     }
@@ -128,7 +106,7 @@
         utility::tuple_to_array(std::make_tuple('\0'));
     % else:
         utility::tuple_to_array(message::types::type_id<
-                ${ parameters_types_as_list() }>());
+                ${ method.parameter_types_as_list(interface) }>());
     % endif
 static const auto _return_${ method.CamelCase } =
     % if len(method.returns) == 0: