[systemd-devel] [PATCH 1/2] Optimize startswith() to macro

WANG Chao chaowang at redhat.com
Thu Aug 22 08:03:11 PDT 2013


On 08/22/13 at 06:53am, Zbigniew Jędrzejewski-Szmek wrote:
> On Thu, Aug 22, 2013 at 03:52:29AM +0200, Kay Sievers wrote:
> > On Wed, Aug 21, 2013 at 10:16 PM, Kay Sievers <kay at vrfy.org> wrote:
> > > On Wed, Aug 21, 2013 at 8:15 PM, WANG Chao <chaowang at redhat.com> wrote:
> > >> Take this optimized code from Lennart[1]. Now startswith is a macro using
> > >> strncmp and should be fast enough.
> > >>
> > >> [1]: http://lists.freedesktop.org/archives/systemd-devel/2013-July/011860.html
> > >> ---
> > >>  src/shared/macro.h |  5 +++++
> > >>  src/shared/util.c  | 17 -----------------
> > >>  2 files changed, 5 insertions(+), 17 deletions(-)
> > >
> > > It fails to compile, there are the prototypes in util.h still.
> > > Also quite a few places do not include macro.h ...
> > >
> > > I guess it's easier and cleaner anyway to use simple static inline
> > > functions instead of defines. Patch attached.
> > 
> > Zbigniew, mind checking if that patch makes sense?
> > 
> > You added the hasprefix a while ago, and you also proposed a version
> > to unify the both.
> > We really should get that topic sorted out now. :)
> Looks correct, pushed this along with Shawn's patch.
> 

Hi, guys, I have two more questions:

- Do we need to update endswith() to be static inline and use strncmp
  instead of memcmp. It looks better if we put these two functions at
  the same place (shared/util.h)

- Why not use startswith() instead of first_word()?


Thanks
WANG Chao


More information about the systemd-devel mailing list