Re: [PATCH linux-phy v2 1/4] string.h: Add str_has_proper_prefix()
From: Marek Behún <kabel@kernel.org>
Date: 2022-08-18 19:48:51
Also in:
lkml
On Thu, 18 Aug 2022 22:10:58 +0300 Andy Shevchenko [off-list ref] wrote:
On Wed, Aug 17, 2022 at 11:06 PM Marek Behún [off-list ref] wrote:quoted
Add str_has_proper_prefix(), similar to str_has_prefix(), but requires that the prefix is proper: the string itself must be longer than the prefix. Signed-off-by: Marek Behún <kabel@kernel.org> --- Andy, Kees, could you ack this if it is ok?Seems to me there are too many strlen():s. One is hidden in strncmp().
I thought this was ok cause gcc has optimizations for this in https://github.com/gcc-mirror/gcc/blob/master/gcc/tree-ssa-strlen.cc But now I see that kernel does not declare these functions as inline that call __builtin_strlen()... so probably the optimizations are not used.
Besides not the good naming (what 'proper' means),
The naming comes from similar naming in math: proper subset is as subset that is not equal to the superset. See https://en.wikipedia.org/wiki/Substring : "A proper prefix of a string is not equal to the string itself"
the entire function is not needed. You may simply call str_has_prefix() && p[len] != '\0'; Correct?
Do you mean that I should implement this function to simply return str_has_prefix() && p[len] != '\0' or that this function should not exist at all and I should do that in the code where I would have used the function? Thanks. Marek -- linux-phy mailing list linux-phy@lists.infradead.org https://lists.infradead.org/mailman/listinfo/linux-phy