]> git.ipfire.org Git - people/jschlag/network.git/commitdiff
Cache system_get_processors()
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 23 Sep 2016 19:21:31 +0000 (21:21 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 23 Sep 2016 19:21:31 +0000 (21:21 +0200)
This function is called quite option and hence we cache
the result to speed up code execution

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.system

index bc5f05b180b08c5a370f955c2564fa7cfc2f9379..947fc3046c02ef10f64185058b674b6f2321850a 100644 (file)
 #                                                                             #
 ###############################################################################
 
-_getconf() {
-       getconf $@
-}
+SYSTEM_PROCESSORS=
 
 # Returns the number of online processors
 system_get_processors() {
-       _getconf _NPROCESSORS_ONLN
+       # Cache this since the function is called quite often
+       isset SYSTEM_PROCESSORS || SYSTEM_PROCESSORS=$(__system_get_processors)
+
+       echo ${SYSTEM_PROCESSORS}
+}
+
+__system_get_processors() {
+       getconf _NPROCESSORS_ONLN
 }
 
 system_get_next_processor() {