[systemd-devel] [PATCH] shared: rename hasprefix() to startswith(), which is functionally identical and removed

Kay Sievers kay at vrfy.org
Fri Jul 12 09:09:06 PDT 2013


On Fri, Jul 12, 2013 at 5:35 PM, Shawn Landden <shawnlandden at gmail.com> wrote:
> as most (if not all) of the prefix strings are static, these will get
> forward constant propagation optimized into single memcmp() calls, which
> should be much better than the non-SIMD hand-rolled version.

> -#define hasprefix(s, prefix) (memcmp(s, prefix, strlen(prefix)) == 0)
> +#define startswith(s, prefix) (memcmp(s, prefix, strlen(prefix)) == 0)

What if 's' is shorter than 'prefix'? We should not access the
possibly uninitialized memory?

Also there are users like:
  e = startswith()
which rely on the returned offset. That would go wrong now, right?

I guess we need a smarter version of startswith, maybe one that
behaves different for const values and uses __builtin_constant_p logic
to compile-time optimize it.

Kay


More information about the systemd-devel mailing list