nice speed up for gen deps
authorFred T. Hamster <fred@feistymeow.org>
Wed, 11 Feb 2026 07:10:59 +0000 (02:10 -0500)
committerFred T. Hamster <fred@feistymeow.org>
Wed, 11 Feb 2026 07:10:59 +0000 (02:10 -0500)
using less calls out to sed now, and found a more efficient array search.
that being said, we probably need to move to associative arrays instead of normal ones,
and that will be wicked faster.

scripts/clam/cpp/buildor_gen_deps.sh

index 063370f0c0a5596f63b068cad0fc21bc7296d9ab..bb0e958a9c2eeda74fa82892be8e625b9fc3b604 100644 (file)
@@ -92,30 +92,49 @@ function add_new_dep {
 # listed.  if this is the case, zero is returned (meaning success).  if
 # the dependency is missing, then -1 is return to indicate an error.
 function existing_dep {
-#hmmm: below is not very efficient!
-  for currite in ${dependency_accumulator[*]}; do
-    if [ "$currite" == "$1" ]; then return 0; fi
-  done
+  seek="$1"; shift
+  # efficient search of array for the string.
+  if ( IFS=$'\n'; echo "${dependency_accumulator[*]}" ) | grep -qFx "$seek"; then
+    return 0
+  fi
+
+## #hmmm: below is not very efficient!
+##   for currite in ${dependency_accumulator[*]}; do
+##     if [ "$currite" == "$1" ]; then return 0; fi
+##   done
+
   return 1
 }
 
 # reports whether a file name has already been processed.
 function boring_file {
+  seek="$1"; shift
+  # efficient search of array for the string.
+  if ( IFS=$'\n'; echo "${boring_files[*]}" ) | grep -qFx "$seek"; then
+    return 0
+  fi
+
+## #hmmm: below might not be very efficient!
+##   for currite in ${boring_files[*]}; do
+##     if [ "$currite" == "$1" ]; then return 0; fi
+##   done
 
-#hmmm: below might not be very efficient!
-  for currite in ${boring_files[*]}; do
-    if [ "$currite" == "$1" ]; then return 0; fi
-  done
   return 1
 }
 
 # reports whether a file name has already been found to be missing.
 function bad_file {
+  seek="$1"; shift
+  # efficient search of array for the string.
+  if ( IFS=$'\n'; echo "${bad_files[*]}" ) | grep -qFx "$seek"; then
+    return 0
+  fi
+
+## #hmmm: below also is not very efficient!
+##   for currite in ${bad_files[*]}; do
+##     if [ "$currite" == "$seek" ]; then return 0; fi
+##   done
 
-#hmmm: below also is not very efficient!
-  for currite in ${bad_files[*]}; do
-    if [ "$currite" == "$1" ]; then return 0; fi
-  done
   return 1
 }
 
@@ -253,6 +272,7 @@ function recurse_on_deps {
 
   local dirtmp=$(dirname "$to_examine")
   local basetmp=$(basename "$to_examine")
+
   log_it "dependent on: $(basename "$dirtmp")/$basetmp"
 #hmmm: do a better, nicer output--gather the dependencies listed in debugging
 #      line above into a list that will be printed out at the end.
@@ -271,9 +291,9 @@ function recurse_on_deps {
 
   # find all the includes in this file and save to the temp file.
   while read -r spoon; do
-    has_guard="$(echo "$spoon" \
-        | sed -n -e 's/#ifdef __BUILD_STATIC_APPLICATION__/yep/p')" 
-    if [ ! -z "$has_guard" ]; then
+#    has_guard="$(echo "$spoon" | sed -n -e 's/#ifdef __BUILD_STATIC_APPLICATION__/yep/p')" 
+#    if [ ! -z "$has_guard" ]; then
+    if [[ $spoon == *"#ifdef __BUILD_STATIC_APPLICATION__"* ]]; then
       # quit reading when we've seen the start of one of our guards.
       break
     fi
@@ -296,9 +316,10 @@ function recurse_on_deps {
   # iterate across the dependencies we saw and add them to our list if we haven't already.
   while read -r line_found; do
     # process the line to see if we can get a simple filename out of the include.
+    # we are only trying for system-searched files for this one, with angle brackets.
     #local chew_toy=$(echo $line_found | sed -e 's/^[ \t]*#include *<\(.*\)>.*$/\1/')
-    local chew_toy="${line_found#*\#include *[\"<]}"
-    chew_toy="${chew_toy/[\">]*}"
+    local chew_toy="${line_found#*\#include *<}"
+    chew_toy="${chew_toy/>*}"
     if [ ! -z "$DEBUG_BUILDOR_GEN_DEPS" ]; then
       log_it A: chew_toy=$chew_toy
     fi
@@ -309,43 +330,38 @@ function recurse_on_deps {
 #    local slash_present=$(echo $chew_toy | sed -n -e 's/.*[\\\/].*/yep/p')
     local slash_present="${chew_toy/[^\/]*/}"
 
-#this block with the second attempt should no longer be necessary.
-#    # the replacement above to get rid of #include failed.  try something simpler.
 #    if [ ! -z "$(echo $chew_toy | sed -n -e 's/#include/crud/p')" ]; then
-#    if [[ $chew_toy == *"#include"* ]]; then
-
-#      if [ ! -z "$DEBUG_BUILDOR_GEN_DEPS" ]; then
-#        log_it "into b-grade processing; why are we here????"
-#        log_it "line with include in it still is: '$chew_toy'"
-#      fi
-## # try again with a simpler pattern???
-## #      chew_toy=$(echo $line_found | sed -e 's/^[ \t]*#include *[">]\(.*\)[">].*$/\1/') 
-##       chew_toy="${chew_toy#[[:space:]]*#include[[:space:]]*[\"<]}"
-##       chew_toy="${chew_toy/[[:space:]]*[\">]}"
-## #      if [ ! -z "$DEBUG_BUILDOR_GEN_DEPS" ]; then
-##         log_it "B: chew_toy=$chew_toy"
-## #      fi
-
-    # if it still has an #include or if it's not really a file, we can't
-    # use it for anything.
     if [[ $chew_toy == *"#include"* ]]; then
+      # the replacement above to get rid of #include failed.  try something
+      # more inclusive, so we match double quote includes also.
+#      chew_toy=$(echo $line_found | sed -e 's/^[ \t]*#include *[">]\(.*\)[">].*$/\1/') 
+      chew_toy="${chew_toy#*\#include *[\"<]}"
+      chew_toy="${chew_toy/[\">]*}"
+      if [ ! -z "$DEBUG_BUILDOR_GEN_DEPS" ]; then
+        echo B: chew_toy=$chew_toy
+      fi
+
+      # if it still has an #include or if it's not really a file, we can't
+      # use it for anything.
+      if [[ $chew_toy == *"#include"* ]]; then
 #      if [ ! -z "$(echo $chew_toy | sed -n -e 's/#include/crud/p')" ]; then
-      log_it "** bad include: $chew_toy"
-      continue
-    fi
+        log_it "** bad include: $chew_toy"
+        continue
+      fi
 
-    if [ -z "$slash_present" ]; then
-      # we are pretty sure that this file has no path components in it.
-      # we will add the surrounding directory if possible.
-      if [ -z "$fp_dir" ]; then
-        # well, now we have no recourse, since we don't know where to
-        # say this file comes from.
-        log_it "** unknown directory: $chew_toy"
-      else
-        # cool, we can rely on the existing directory.
-        chew_toy="$fp_dir/$chew_toy"
-        if [ ! -z "$DEBUG_BUILDOR_GEN_DEPS" ]; then
-          log_it "patched dir: $chew_toy"
+      if [ -z "$slash_present" ]; then
+        # we are pretty sure that this file has no path components in it.
+        # we will add the surrounding directory if possible.
+        if [ -z "$fp_dir" ]; then
+          # well, now we have no recourse, since we don't know where to
+          # say this file comes from.
+          log_it "** unknown directory: $chew_toy"
+        else
+          # cool, we can rely on the existing directory.
+          chew_toy="$fp_dir/$chew_toy"
+          if [ ! -z "$DEBUG_BUILDOR_GEN_DEPS" ]; then
+            log_it "patched dir: $chew_toy"
+          fi
         fi
       fi
     fi