{"thread":{"id":"52221","subject":"[PATCH] utf8: use skip_iprefix() in same_utf_encoding()","startedAt":"2019-11-08T20:25:34Z","lastAt":"2019-11-08T22:20:50Z","messageCount":2,"participants":["René Scharfe","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"385807","messageId":"b27cc95d-8cb8-db49-c2d1-3eb591624000@web.de","threadId":"52221","inReplyTo":null,"subject":"[PATCH] utf8: use skip_iprefix() in same_utf_encoding()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2019-11-08T20:25:21Z","receivedAt":"2019-11-08T20:25:34Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Get rid of magic numbers by using skip_iprefix() and skip_prefix() for\nparsing the leading \"[uU][tT][fF]-?\" of both strings instead of checking\nwith istarts_with() and an explicit comparison.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n utf8.c | 9 ++++-----\n 1 file changed, 4 insertions(+), 5 deletions(-)\n\ndiff --git a/utf8.c b/utf8.c\nindex 5c8f151f75..5b39361ada 100644\n--- a/utf8.c\n+++ b/utf8.c\n@@ -411,11 +411,10 @@ void strbuf_utf8_replace(struct strbuf *sb_src, int pos, int width,\n  */\n static int same_utf_encoding(const char *src, const char *dst)\n {\n-\tif (istarts_with(src, \"utf\") && istarts_with(dst, \"utf\")) {\n-\t\t/* src[3] or dst[3] might be '\\0' */\n-\t\tint i = (src[3] == '-' ? 4 : 3);\n-\t\tint j = (dst[3] == '-' ? 4 : 3);\n-\t\treturn !strcasecmp(src+i, dst+j);\n+\tif (skip_iprefix(src, \"utf\", &src) && skip_iprefix(dst, \"utf\", &dst)) {\n+\t\tskip_prefix(src, \"-\", &src);\n+\t\tskip_prefix(dst, \"-\", &dst);\n+\t\treturn !strcasecmp(src, dst);\n \t}\n \treturn 0;\n }\n--\n2.24.0\n"},{"id":"385819","messageId":"20191108222048.GA18554@sigill.intra.peff.net","threadId":"52221","inReplyTo":"b27cc95d-8cb8-db49-c2d1-3eb591624000@web.de","subject":"Re: [PATCH] utf8: use skip_iprefix() in same_utf_encoding()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-11-08T22:20:48Z","receivedAt":"2019-11-08T22:20:50Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Nov 08, 2019 at 09:25:21PM +0100, René Scharfe wrote:\n\n> Get rid of magic numbers by using skip_iprefix() and skip_prefix() for\n> parsing the leading \"[uU][tT][fF]-?\" of both strings instead of checking\n> with istarts_with() and an explicit comparison.\n\nYeah, I think the result is much easier to understand. I didn't look\nclosely at it, but the generated asm seems to be slightly shorter, too.\n\n-Peff\n"}]}