git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@jeffhostetler.com
Cc: git@vger.kernel.org, peff@peff.net,
	Jeff Hostetler <jeffhost@microsoft.com>
Subject: Re: [PATCH v9] json_writer: new routines to create JSON data
Date: Tue, 12 Jun 2018 13:49:19 -0700	[thread overview]
Message-ID: <xmqqfu1r91dc.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20180612202201.94733-2-git@jeffhostetler.com> (git's message of "Tue, 12 Jun 2018 20:22:01 +0000")

git@jeffhostetler.com writes:


> +static void indent_pretty(struct json_writer *jw)
> +{
> +	int k;
> +
> +	if (!jw->pretty)
> +		return;
> +
> +	for (k = 0; k < jw->open_stack.len; k++)
> +		strbuf_addstr(&jw->json, "  ");
> +}

> +static void array_common(struct json_writer *jw)
> +{
> +	assert_in_array(jw);
> +	maybe_add_comma(jw);
> +
> +	if (jw->pretty)
> +		strbuf_addch(&jw->json, '\n');
> +	indent_pretty(jw);

Make it

	if (jw->pretty) {
		strbuf_addch(&jw->json, '\n');
		indent_pretty(jw);
	}

and lose "be noop unless jw->pretty" check from the indent function.

Most other codepaths that cares about pretty printing state use that
"I check and decide to (or not to) call helpers that unconditionally
do" pattern, and the way indent_pretty() is used in the patch stands
out like a sore thumb.


      parent reply	other threads:[~2018-06-12 20:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-12 20:22 [PATCH v9] json_writer V9 git
2018-06-12 20:22 ` [PATCH v9] json_writer: new routines to create JSON data git
2018-06-12 20:30   ` Eric Sunshine
2018-06-12 20:49   ` Junio C Hamano [this message]

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=xmqqfu1r91dc.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@jeffhostetler.com \
    --cc=git@vger.kernel.org \
    --cc=jeffhost@microsoft.com \
    --cc=peff@peff.net \
    /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).