From: ori@eigenstate.org
To: 9front@9front.org
Subject: Re: [9front] [PATCH] silence drawterm runestrchr while(assign) warning
Date: Mon, 30 May 2022 01:15:20 -0400 [thread overview]
Message-ID: <E15E8CE8D6B030269CF0B27C85FE9703@eigenstate.org> (raw)
In-Reply-To: <20220522180436.6c17d808@spruce.localdomain>
Quoth Amavect <amavect@gmail.com>:
> Hi,
>
> I want to shut up drawterm compile warnings without resorting to -Wno.
> I'll rationalize this with reducing function sizes by bytes,
> "improving readability", and micro optimizations for kencc.
>
> Here are some basic transformations on strchr and runestrchr.
> It reduces 9front function byte sizes on the arches I tested
> (amd64 0x4f->0x43, arm 0x50->0x40, power 0x68->0x5c).
> It shuts up a gcc warning about runestrchr while(c1 = *s++)
> (when compiled without -Wno-parentheses)
> Attached are patches for 9front and drawterm.
> Below are the full functions for criticism.
Looks fine to me, thanks.
Committed locally, will push tomorrow after I take a second,
well rested look.
Will also toss your unit tests into the regress test repo.
> Thanks,
> Amavect
>
>
> char*
> strchr(char *s, int c)
> {
> char r;
>
> if(c == 0)
> while(*s++)
> ;
> else
> while((r = *s++) != c)
> if(r == 0)
> return 0;
> return s-1;
> }
>
>
> Rune*
> runestrchr(Rune *s, Rune c)
> {
> Rune r;
>
> if(c == 0)
> while(*s++)
> ;
> else
> while((r = *s++) != c)
> if(r == 0)
> return 0;
> return s-1;
> }
>
>
> unit test:
>
> #include <u.h>
> #include <libc.h>
>
> void
> main(void)
> {
> char *v = "foo bar ss";
> char *e;
> Rune *c = L"foo βαρ ß";
> Rune *t;
>
> e = strchr(v, L'z');
> assert(e == nil);
> e = strchr(v, L'a');
> assert(e == v+5);
> e = strchr(v, 0);
> assert(e == v+10);
>
> t = runestrchr(c, L'z');
> assert(t == nil);
> t = runestrchr(c, L'α');
> assert(t == c+5);
> t = runestrchr(c, 0);
> assert(t == c+9);
> }
>
prev parent reply other threads:[~2022-05-30 5:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-22 23:04 Amavect
2022-05-30 1:02 ` [9front] " Amavect
2022-05-30 5:15 ` ori [this message]
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=E15E8CE8D6B030269CF0B27C85FE9703@eigenstate.org \
--to=ori@eigenstate.org \
--cc=9front@9front.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).