From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Jan Kiszka <jan.kiszka@siemens.com>
Cc: konrad.schwarz@gmail.com, qemu-devel@nongnu.org,
philmd@linaro.org, Konrad Schwarz <konrad.schwarz@siemens.com>
Subject: Re: [PATCH 1/1] scripts: Changed potential O(n) file size calculation to O(1)
Date: Fri, 21 Nov 2025 11:09:07 +0000 [thread overview]
Message-ID: <aSBIUz8PxYZHncVN@redhat.com> (raw)
In-Reply-To: <dee22f22-c2e5-4154-99a7-525bfeb965af@siemens.com>
On Fri, Nov 21, 2025 at 11:16:11AM +0100, Jan Kiszka wrote:
> You want to add
>
> From: Konrad Schwarz <konrad.schwarz@siemens.com>
>
> to the top of the commit message when submitting via a different account
> so that author and signer are aligned. Or use git sendemail which will
> do that when author and submitter address differ.
>
> On 19.11.25 18:28, konrad.schwarz@gmail.com wrote:
> > The mkemmc.sh script calculates file sizes via `wc -c'. `wc'
> > normally works by reading the entire file, resulting in O(n) performance.
> >
> > Unix file systems obviously know a file's size and POSIX `ls' reports this
> > information unambiguously, so replacing `wc' with `ls' ensures O(1)
> > performance. The files in question tend to be large making this change
> > worthwhile.
>
> Valid point.
>
> >
> > Signed-off-by: Konrad Schwarz <konrad.schwarz@siemens.com>
> > ---
> > scripts/mkemmc.sh | 10 ++++++++--
> > 1 file changed, 8 insertions(+), 2 deletions(-)
> >
> > diff --git a/scripts/mkemmc.sh b/scripts/mkemmc.sh
> > index 45dc3f08fa..d2c4e84b16 100755
> > --- a/scripts/mkemmc.sh
> > +++ b/scripts/mkemmc.sh
> > @@ -37,13 +37,19 @@ usage() {
> > exit "$1"
> > }
> >
> > +file_size() {
> > + ls_line=$(ls -Hdog "$1") || return
>
> This will not suppress the error message when a file does not exist or
> is not accessible, so:
>
> ls_line=$(ls -Hdog "$1" 2>/dev/null) || return
>
> > + printf %s\\n "$ls_line" | cut -d\ -f3
> > + unset ls_line
This parsing of 'ls' output could be simplified by
using the 'stat' command with a format string to
request only the file size.
stat --format=%s "$1"
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2025-11-22 3:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-19 17:28 [PATCH 1/1] scripts: Changed potential O(n) file size calculation to O(1) konrad.schwarz
2025-11-21 10:16 ` Jan Kiszka
2025-11-21 11:09 ` Daniel P. Berrangé [this message]
2025-11-21 14:07 ` Schwarz, Konrad
2025-11-21 13:32 ` Schwarz, Konrad
2025-11-21 14:10 ` Jan Kiszka
2025-11-21 12:25 ` Paolo Bonzini
[not found] ` <AS8PR10MB4680FED05DB882C0C7751E058AD5A@AS8PR10MB4680.EURPRD10.PROD.OUTLOOK.COM>
[not found] ` <CABgObfb89UUyha3xz5d2MihRkg2WKBTpUOiNMA5o8oPE=MBMyQ@mail.gmail.com>
2025-11-21 14:57 ` Schwarz, Konrad
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aSBIUz8PxYZHncVN@redhat.com \
--to=berrange@redhat.com \
--cc=jan.kiszka@siemens.com \
--cc=konrad.schwarz@gmail.com \
--cc=konrad.schwarz@siemens.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).