From 7cd7d838cf57f184fd58c05e30588fb1a2fcf6b2 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 7 May 2023 17:29:18 +0200 Subject: [PATCH] modalias.prov: group modalias lines by length On my machine, out of 2604 modules, this reduces number of "provides" items by ~800 (to 12689 items). Signed-off-by: Denys Vlasenko --- modalias.prov | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modalias.prov b/modalias.prov index 9ee34c2..f362fd3 100755 --- a/modalias.prov +++ b/modalias.prov @@ -51,14 +51,14 @@ print_modaliases() { # replace with # modalias(pci:v0000168Cd0000002[3479]sv*sd*bc*sc*i*) combine_modaliases() { - local tag class variants="" pos="" n + local unused_len tag class variants="" pos="" n # Due to set -e, we can exit with exitcode 1 on read EOF # and this makes our caller think we failed. "|| return 0" prevents this: - read class || return 0 + IFS=' ' read unused_len class || return 0 # For each line after the first... - while read tag; do + while IFS=' ' read unused_len tag; do # For each char in prev line... for ((n=0; n<${#class}; n++)); do # If aaaNbbb = aaaMbbb and N isn't "*" @@ -95,6 +95,11 @@ for module in $(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz|\.zst)?$') "$@"; do /sbin/modinfo -F alias "$module" \ | sed -nre "s,[^][0-9a-zA-Z._:*?/-],_,g; s,(.+),modalias(\\1)$modver,p" + + # Below: combining code can only possibly combine lines of equal length. + # Prepend line lengths before sort, so that same-length lines end up next + # to each other. (The lengths are discarded by combine_modaliases). done \ +| { while read line; do echo "${#line} $line"; done } \ | LC_ALL=C sort -u \ | combine_modaliases