On Thu, Aug 22, 2013 at 11:03:11PM +0800, WANG Chao wrote: > 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 <k...@vrfy.org> wrote: > > > > On Wed, Aug 21, 2013 at 8:15 PM, WANG Chao <chaow...@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) Sounds useful.
> - Why not use startswith() instead of first_word()? first_word is not equivalent: there must be a word boundary after the word: src/test/test-util.c:static void test_first_word(void) { src/test/test-util.c: assert_se(first_word("Hello", "")); src/test/test-util.c: assert_se(first_word("Hello", "Hello")); src/test/test-util.c: assert_se(first_word("Hello world", "Hello")); src/test/test-util.c: assert_se(first_word("Hello\tworld", "Hello")); src/test/test-util.c: assert_se(first_word("Hello\nworld", "Hello")); src/test/test-util.c: assert_se(first_word("Hello\rworld", "Hello")); src/test/test-util.c: assert_se(first_word("Hello ", "Hello")); src/test/test-util.c: assert_se(!first_word("Hello", "Hellooo")); src/test/test-util.c: assert_se(!first_word("Hello", "xxxxx")); src/test/test-util.c: assert_se(!first_word("Hellooo", "Hello")); Zbyszek _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel