[Pkg-acpi-devel] Bug#593996: acpi-support: resource waste; unnecessary forks and pipes

Cristian Ionescu-Idbohrn cristian.ionescu-idbohrn at axis.com
Mon Nov 15 14:15:45 UTC 2010


On Mon, 15 Nov 2010, Michael Meskes wrote:
>
> On Sun, Aug 22, 2010 at 11:39:02PM +0200, Cristian Ionescu-Idbohrn wrote:
> > This is one example:
> >
> > lib/device-funcs:6:    bios_version=`cat /sys/class/dmi/id/bios_version|sed -e 's/ *$//'`
> >
> > Save a fork and a pipe by simply:
> >
> > bios_version=$(sed -re 's/[[:blank:]]+*$//' /sys/class/dmi/id/bios_version)
                                         ^
> Is there a reason for changing the sed expression, too?

I do think its more robust.  You'll be matching not only SPACE but
also TAB characters.  And, by the way, the regex is wrong.  Should be:

bios_version=$(sed -re 's/[[:blank:]]*$//' /sys/class/dmi/id/bios_version)

Is the intention to remove horisontal whitespace occurence, at the
enf-of-line, or something else?

There's also:

read bios_version </sys/class/dmi/id/bios_version
bios_version=$(echo bios_version)

> > This is the 3rd:
> >
> > lib/state-funcs:5:WLAN_RFKILLS=`for RFKILL in /sys/class/rfkill/rfkill*; do if [ $(cat $RFKILL/type) = wlan ]; then echo $RFKILL/state; fi; done`
> >
> > vs. (builtin 'read' is some 30x faster than a 'cat' fork):
> >
> > WLAN_RFKILLS=$(for RFKILL in /sys/class/rfkill/rfkill*; do
> > 			read rfk <$RFKILL >/dev/null || :
> > 			[ "$rfk" != wlan ] || echo $RFKILL/state
> > 		done)
>
> I take it you lost "/type" in this change right?

Yes, I did.

> > Similar examples can be found in a lot of other places.
>
> So feel free to send a patch.

That would be quite a few patches :)
Lots of scripts.  Any particulary interesting place to start?


Cheers,

-- 
Cristian





More information about the Pkg-acpi-devel mailing list