From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Tremer To: network@lists.ipfire.org Subject: Re: [PATCH 4/5] config: add new functions Date: Mon, 17 Jul 2017 16:22:46 -0400 Message-ID: <1500322966.2548.10.camel@ipfire.org> In-Reply-To: <1500305066-12510-4-git-send-email-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1950037572907198687==" List-Id: --===============1950037572907198687== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Hi, On Mon, 2017-07-17 at 17:24 +0200, Jonatan Schlag wrote: > This patch add two new functions: > config_get_id_from_config() > config_get_hook_from_config > > Signed-off-by: Jonatan Schlag > --- >  src/functions/functions.config | 20 ++++++++++++++++++++ >  1 file changed, 20 insertions(+) > > diff --git a/src/functions/functions.config > b/src/functions/functions.config > index 854f490..e11a1c2 100644 > --- a/src/functions/functions.config > +++ b/src/functions/functions.config > @@ -51,3 +51,23 @@ config_domainname() { >   # the domain part. >   print "${hostname#*.}" >  } > + > +config_get_id_from_config() { > + # This function returns the id for a given config name > + # Example 'dhcp.0' => 0 > + assert [ $# -eq 1 ] > + local config=${1} > + > + local hook=$(config_get_hook_from_config ${config}) > + echo "${config//"${hook}."/}" > + > +} There is an extra empty line. And calling config_get_hook_from_config() is an expensive call. It forks a subshell and loads the hook and so on. I am sure that you can find the ID without knowing what is coming before. That would increase performance of this function tremendously. > + > +config_get_hook_from_config() { > + # This function returns the hook for a given config name > + # Example 'dhcp.0' => dhcp > + assert [ $# -eq 1 ] > + local config=${1} > + > + echo "${config//.*[[:digit:]]/}" > +} --===============1950037572907198687== Content-Type: application/pgp-signature Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="signature.asc" MIME-Version: 1.0 LS0tLS1CRUdJTiBQR1AgU0lHTkFUVVJFLS0tLS0KVmVyc2lvbjogR251UEcgdjIKCmlRSWNCQUFC Q2dBR0JRSlpiUnlXQUFvSkVJQjU4UDl2a0FrSEYwY1AvUkU3U1VDejJMM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