Chris Down <[email protected]> writes: > diff --git a/src/sort.c b/src/sort.c > index e20ed2c8f..aaab47b50 100644 > --- a/src/sort.c > +++ b/src/sort.c > @@ -1725,8 +1725,8 @@ begfield (struct line const *line, struct keyfield > const *key) > if (tab != TAB_DEFAULT) > while (ptr < lim && sword--) > { > - while (ptr < lim && *ptr != tab) > - ++ptr; > + char *sep = memchr (ptr, tab, (size_t) (lim - ptr)); > + ptr = sep ? sep : lim; > if (ptr < lim) > ++ptr; > } > @@ -1778,8 +1778,8 @@ limfield (struct line const *line, struct keyfield > const *key) > if (tab != TAB_DEFAULT) > while (ptr < lim && eword--) > { > - while (ptr < lim && *ptr != tab) > - ++ptr; > + char *sep = memchr (ptr, tab, (size_t) (lim - ptr)); > + ptr = sep ? sep : lim; > if (ptr < lim && (eword || echar)) > ++ptr; > }
Thanks for the patch and detailed benchmarks! I just pushed a tiny patch to avoid the size_t casts. Nothing saying your patch is wrong, it is just most of us prefer to avoid them. Collin
>From 430822d5f71ff95bc813ddc254d559d808177d57 Mon Sep 17 00:00:00 2001 Message-ID: <430822d5f71ff95bc813ddc254d559d808177d57.1774320260.git.collin.fu...@gmail.com> From: Collin Funk <[email protected]> Date: Mon, 23 Mar 2026 19:32:21 -0700 Subject: [PATCH] maint: remove some unnecessary casts * src/sort.c (begfield, limfield): Remove size_t casts. --- src/sort.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sort.c b/src/sort.c index aaab47b50..510c674d9 100644 --- a/src/sort.c +++ b/src/sort.c @@ -1725,7 +1725,7 @@ begfield (struct line const *line, struct keyfield const *key) if (tab != TAB_DEFAULT) while (ptr < lim && sword--) { - char *sep = memchr (ptr, tab, (size_t) (lim - ptr)); + char *sep = memchr (ptr, tab, lim - ptr); ptr = sep ? sep : lim; if (ptr < lim) ++ptr; @@ -1778,7 +1778,7 @@ limfield (struct line const *line, struct keyfield const *key) if (tab != TAB_DEFAULT) while (ptr < lim && eword--) { - char *sep = memchr (ptr, tab, (size_t) (lim - ptr)); + char *sep = memchr (ptr, tab, lim - ptr); ptr = sep ? sep : lim; if (ptr < lim && (eword || echar)) ++ptr; -- 2.53.0
