git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Hariom verma <hariom18599@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Hariom Verma via GitGitGadget <gitgitgadget@gmail.com>,
	git <git@vger.kernel.org>,
	Christian Couder <christian.couder@gmail.com>,
	Heba Waly <heba.waly@gmail.com>
Subject: Re: [PATCH v3 7/9] pretty: refactor `format_sanitized_subject()`
Date: Wed, 19 Aug 2020 19:06:59 +0530	[thread overview]
Message-ID: <CA+CkUQ9tkwXmrHq_ZV+RCgwoFHZ0M4dEhBkjUd97Xi+3shB-WQ@mail.gmail.com> (raw)
In-Reply-To: <xmqqpn7p1373.fsf@gitster.c.googlers.com>

Hi Junio,

On Tue, Aug 18, 2020 at 12:59 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> "Hariom Verma via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > -static void format_sanitized_subject(struct strbuf *sb, const char *msg)
> > +static void format_sanitized_subject(struct strbuf *sb, const char *msg, size_t len)
> >  {
> > +     char *r = xmemdupz(msg, len);
> >       size_t trimlen;
> >       size_t start_len = sb->len;
> >       int space = 2;
> > +     int i;
> >
> > -     for (; *msg && *msg != '\n'; msg++) {
> > -             if (istitlechar(*msg)) {
> > +     for (i = 0; i < len; i++) {
> > +             if (r[i] == '\n')
> > +                     r[i] = ' ';
>
> Copying the whole string only for this one looks very wasteful.
> Can't you do
>
>         for (i = 0; i < len; i++) {
>                 char r = msg[i];
>                 if (isspace(r))
>                         r = ' ';
>                 if (istitlechar(r)) {
>                         ...
>         }
>
> or something like that instead?

Ok, that sounds better. Noted for the next version.

> > +             if (istitlechar(r[i])) {
> >                       if (space == 1)
> >                               strbuf_addch(sb, '-');
> >                       space = 0;
> > -                     strbuf_addch(sb, *msg);
> > -                     if (*msg == '.')
> > -                             while (*(msg+1) == '.')
> > -                                     msg++;
> > +                     strbuf_addch(sb, r[i]);
> > +                     if (r[i] == '.')
> > +                             while (r[i+1] == '.')
> > +                                     i++;
> >               } else
> >                       space |= 1;
> >       }
> > +     free(r);
>
> Also, because neither LF or SP is a titlechar(), wouldn't the "if
> r[i] is LF, replace it with SP" a no-op wrt what will be in sb at
> the end?

Maybe its better to directly replace LF with hyphen? [Instead of first
replacing LF with SP and then replacing SP with '-'.]

> >       case 'f':       /* sanitized subject */
> > -             format_sanitized_subject(sb, msg + c->subject_off);
> > +             eol = strchrnul(msg + c->subject_off, '\n');
> > +             format_sanitized_subject(sb, msg + c->subject_off, eol - (msg + c->subject_off));
>
> This original caller expected the helper to stop reading at the end
> of the first line, but the updated helper needs to be told where to
> stop, so we do so with some extra computation.  Makes sense.

Yeah.

Thanks,
Hariom

  reply	other threads:[~2020-08-19 13:37 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-27 20:43 [PATCH 0/5] [GSoC] Improvements to ref-filter Hariom Verma via GitGitGadget
2020-07-27 20:43 ` [PATCH 1/5] ref-filter: support different email formats Hariom Verma via GitGitGadget
2020-07-27 22:51   ` Junio C Hamano
2020-07-28 20:31     ` Hariom verma
2020-07-28 20:43       ` Junio C Hamano
2020-07-28 13:58   ` Đoàn Trần Công Danh
2020-07-28 16:45     ` Junio C Hamano
2020-07-27 20:43 ` [PATCH 2/5] ref-filter: add `short` option for 'tree' and 'parent' Hariom Verma via GitGitGadget
2020-07-27 23:21   ` Junio C Hamano
2020-07-27 20:43 ` [PATCH 3/5] pretty: refactor `format_sanitized_subject()` Hariom Verma via GitGitGadget
2020-07-27 20:43 ` [PATCH 4/5] format-support: move `format_sanitized_subject()` from pretty Hariom Verma via GitGitGadget
2020-07-27 20:43 ` [PATCH 5/5] ref-filter: add `sanitize` option for 'subject' atom Hariom Verma via GitGitGadget
2020-08-05 21:51 ` [PATCH v2 0/9] [GSoC] Improvements to ref-filter Hariom Verma via GitGitGadget
2020-08-05 21:51   ` [PATCH v2 1/9] ref-filter: support different email formats Hariom Verma via GitGitGadget
2020-08-05 21:51   ` [PATCH v2 2/9] ref-filter: refactor `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-05 21:51   ` [PATCH v2 3/9] ref-filter: modify error messages in `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-05 21:51   ` [PATCH v2 4/9] ref-filter: rename `objectname` related functions and fields Hariom Verma via GitGitGadget
2020-08-05 21:51   ` [PATCH v2 5/9] ref-filter: add `short` modifier to 'tree' atom Hariom Verma via GitGitGadget
2020-08-05 21:51   ` [PATCH v2 6/9] ref-filter: add `short` modifier to 'parent' atom Hariom Verma via GitGitGadget
2020-08-05 21:51   ` [PATCH v2 7/9] pretty: refactor `format_sanitized_subject()` Hariom Verma via GitGitGadget
2020-08-05 21:51   ` [PATCH v2 8/9] format-support: move `format_sanitized_subject()` from pretty Hariom Verma via GitGitGadget
2020-08-05 21:51   ` [PATCH v2 9/9] ref-filter: add `sanitize` option for 'subject' atom Hariom Verma via GitGitGadget
2020-08-05 22:04   ` [PATCH v2 0/9] [GSoC] Improvements to ref-filter Junio C Hamano
2020-08-06 13:47     ` Hariom verma
2020-08-17 18:10   ` [PATCH v3 0/9] [Resend][GSoC] " Hariom Verma via GitGitGadget
2020-08-17 18:10     ` [PATCH v3 1/9] ref-filter: support different email formats Hariom Verma via GitGitGadget
2020-08-17 18:10     ` [PATCH v3 2/9] ref-filter: refactor `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-17 18:10     ` [PATCH v3 3/9] ref-filter: modify error messages in `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-17 18:10     ` [PATCH v3 4/9] ref-filter: rename `objectname` related functions and fields Hariom Verma via GitGitGadget
2020-08-17 18:10     ` [PATCH v3 5/9] ref-filter: add `short` modifier to 'tree' atom Hariom Verma via GitGitGadget
2020-08-17 18:10     ` [PATCH v3 6/9] ref-filter: add `short` modifier to 'parent' atom Hariom Verma via GitGitGadget
2020-08-17 18:10     ` [PATCH v3 7/9] pretty: refactor `format_sanitized_subject()` Hariom Verma via GitGitGadget
2020-08-17 19:29       ` Junio C Hamano
2020-08-19 13:36         ` Hariom verma [this message]
2020-08-19 16:01           ` Junio C Hamano
2020-08-19 16:08             ` Junio C Hamano
2020-08-20 17:33               ` Hariom verma
2020-08-20 17:27             ` Hariom verma
2020-08-17 18:10     ` [PATCH v3 8/9] format-support: move `format_sanitized_subject()` from pretty Hariom Verma via GitGitGadget
2020-08-17 19:33       ` Junio C Hamano
2020-08-17 18:10     ` [PATCH v3 9/9] ref-filter: add `sanitize` option for 'subject' atom Hariom Verma via GitGitGadget
2020-08-17 19:37     ` [PATCH v3 0/9] [Resend][GSoC] Improvements to ref-filter Junio C Hamano
2020-08-21 21:41     ` [PATCH v4 0/8] [GSoC] " Hariom Verma via GitGitGadget
2020-08-21 21:41       ` [PATCH v4 1/8] ref-filter: support different email formats Hariom Verma via GitGitGadget
2020-08-21 21:41       ` [PATCH v4 2/8] ref-filter: refactor `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-21 21:41       ` [PATCH v4 3/8] ref-filter: modify error messages in `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-21 21:41       ` [PATCH v4 4/8] ref-filter: rename `objectname` related functions and fields Hariom Verma via GitGitGadget
2020-08-21 21:41       ` [PATCH v4 5/8] ref-filter: add `short` modifier to 'tree' atom Hariom Verma via GitGitGadget
2020-08-21 21:41       ` [PATCH v4 6/8] ref-filter: add `short` modifier to 'parent' atom Hariom Verma via GitGitGadget
2020-08-21 21:41       ` [PATCH v4 7/8] pretty: refactor `format_sanitized_subject()` Hariom Verma via GitGitGadget
2020-08-21 21:41       ` [PATCH v4 8/8] ref-filter: add `sanitize` option for 'subject' atom Hariom Verma via GitGitGadget

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+CkUQ9tkwXmrHq_ZV+RCgwoFHZ0M4dEhBkjUd97Xi+3shB-WQ@mail.gmail.com \
    --to=hariom18599@gmail.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.com \
    --cc=heba.waly@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).