Re: [PATCH v4 1/6] xdiff/xdl_cleanup_records: delete local recs pointer
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 30, 2026, 22:53 UTC
- Message-ID
- <xmqq7bqt6i9y.fsf@gitster.g>
- In-Reply-To
- <da32a9747c7bde88b4fe33e43ae48c7092d57d9d.1774890003.git.gitgitgadget@gmail.com>
"Ezekiel Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 10 quoted lines
> From: Ezekiel Newren <ezekielnewren@gmail.com> > > Simplify the first 2 for loops by directly indexing the xdfile.recs. > recs is unused in the last 2 for loops, remove it. Best viewed with > --color-words. > > Signed-off-by: Ezekiel Newren <ezekielnewren@gmail.com> > --- > xdiff/xprepare.c | 17 ++++++++--------- > 1 file changed, 8 insertions(+), 9 deletions(-)
Interesting that the latter loops did not even have to have the extra pointer variable. Nice clean-up.
Show 56 quoted lines
>
> diff --git a/xdiff/xprepare.c b/xdiff/xprepare.c
> index cd4fc405eb..d6e1901d2d 100644
> --- a/xdiff/xprepare.c
> +++ b/xdiff/xprepare.c
> @@ -269,7 +269,6 @@ static bool xdl_clean_mmatch(uint8_t const *action, long i, long s, long e) {
> */
> static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xdf2) {
> long i, nm, mlim;
> - xrecord_t *recs;
> xdlclass_t *rcrec;
> uint8_t *action1 = NULL, *action2 = NULL;
> bool need_min = !!(cf->flags & XDF_NEED_MINIMAL);
> @@ -293,16 +292,18 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
> */
> if ((mlim = xdl_bogosqrt((long)xdf1->nrec)) > XDL_MAX_EQLIMIT)
> mlim = XDL_MAX_EQLIMIT;
> - for (i = xdf1->dstart, recs = &xdf1->recs[xdf1->dstart]; i <= xdf1->dend; i++, recs++) {
> - rcrec = cf->rcrecs[recs->minimal_perfect_hash];
> + for (i = xdf1->dstart; i <= xdf1->dend; i++) {
> + size_t mph1 = xdf1->recs[i].minimal_perfect_hash;
> + rcrec = cf->rcrecs[mph1];
> nm = rcrec ? rcrec->len2 : 0;
> action1[i] = (nm == 0) ? DISCARD: (nm >= mlim && !need_min) ? INVESTIGATE: KEEP;
> }
>
> if ((mlim = xdl_bogosqrt((long)xdf2->nrec)) > XDL_MAX_EQLIMIT)
> mlim = XDL_MAX_EQLIMIT;
> - for (i = xdf2->dstart, recs = &xdf2->recs[xdf2->dstart]; i <= xdf2->dend; i++, recs++) {
> - rcrec = cf->rcrecs[recs->minimal_perfect_hash];
> + for (i = xdf2->dstart; i <= xdf2->dend; i++) {
> + size_t mph2 = xdf2->recs[i].minimal_perfect_hash;
> + rcrec = cf->rcrecs[mph2];
> nm = rcrec ? rcrec->len1 : 0;
> action2[i] = (nm == 0) ? DISCARD: (nm >= mlim && !need_min) ? INVESTIGATE: KEEP;
> }
> @@ -312,8 +313,7 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
> * false, or become true.
> */
> xdf1->nreff = 0;
> - for (i = xdf1->dstart, recs = &xdf1->recs[xdf1->dstart];
> - i <= xdf1->dend; i++, recs++) {
> + for (i = xdf1->dstart; i <= xdf1->dend; i++) {
> if (action1[i] == KEEP ||
> (action1[i] == INVESTIGATE && !xdl_clean_mmatch(action1, i, xdf1->dstart, xdf1->dend))) {
> xdf1->reference_index[xdf1->nreff++] = i;
> @@ -324,8 +324,7 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
> }
>
> xdf2->nreff = 0;
> - for (i = xdf2->dstart, recs = &xdf2->recs[xdf2->dstart];
> - i <= xdf2->dend; i++, recs++) {
> + for (i = xdf2->dstart; i <= xdf2->dend; i++) {
> if (action2[i] == KEEP ||
> (action2[i] == INVESTIGATE && !xdl_clean_mmatch(action2, i, xdf2->dstart, xdf2->dend))) {
> xdf2->reference_index[xdf2->nreff++] = i;