From 827f4bf67eafc5a15aaa69cdb465497f4e0f954f Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 31 Jan 2011 11:59:45 -0600 Subject: Keep an array of added modules to prevent expensive lookups This saves a find and grep call for every module that is added more than once, which can lead to significant savings in image generation time. Generating a fallback image went from 80 seconds to 60 seconds after this patch. Signed-off-by: Dan McGee --- functions | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'functions') diff --git a/functions b/functions index bd0a2c6..4cd3136 100644 --- a/functions +++ b/functions @@ -178,6 +178,7 @@ add_file () } HAS_MODULES="n" +declare -a ADDED_MODULES #modules are handled specially in order to enable autodetection add_module () { @@ -186,13 +187,14 @@ add_module () #find pattern - replace _ with [-_] to match either fil="${m//_/[-_]}" + #skip expensive stuff if this module has already been added + if in_array $m ${ADDED_MODULES[@]}; then + msg "module $m was already added" + return + fi + found=0 for path in $(find "${MODULEDIR}" -type f -name "${fil}.ko" -or -name "${fil}.ko.gz"); do - #skip expensive stuff if this module has already been added - if grep -q "file ${path} " "${FILELIST}"; then - found=1 - continue - fi #get needed firmware files for fw in $(/sbin/modinfo -F firmware "${path}"); do [ -f "/lib/firmware/$fw" ] && add_file "/lib/firmware/$fw" @@ -205,6 +207,7 @@ add_module () fi done HAS_MODULES="y" + ADDED_MODULES[${#ADDED_MODULES[*]}]="$m" msg " adding module ${fil}" add_file "${path}" && found=1 done -- cgit v1.2.3-24-g4f1b