Message ID | a8ce6f0d-f0f2-4467-bf16-e7ce78c6ce2d@gmail.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | `--whitespace=fix` with `--no-ignore-whitespace` | expand |
Rubén Justo <rjusto@gmail.com> writes: > It does not make sense to construct an error message if we're not > going to use it, especially when the process involves memory > allocations that need to be freed immediately. > > If we know in advance that we won't use the message, not getting it > slightly reduces the workload and simplifies the code a bit. Makes sense. > > Do it. No need to say this when the above two paragraphs are clear enough, like in this patch. > > Signed-off-by: Rubén Justo <rjusto@gmail.com> > --- > apply.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/apply.c b/apply.c > index e1b4d14dba..e6df8b6ab4 100644 > --- a/apply.c > +++ b/apply.c > @@ -1642,8 +1642,6 @@ static void record_ws_error(struct apply_state *state, > int len, > int linenr) > { > - char *err; > - > if (!result) > return; > > @@ -1652,11 +1650,12 @@ static void record_ws_error(struct apply_state *state, > state->squelch_whitespace_errors < state->whitespace_error) > return; > > - err = whitespace_error_string(result); > - if (state->apply_verbosity > verbosity_silent) > + if (state->apply_verbosity > verbosity_silent) { > + char *err = whitespace_error_string(result); > fprintf(stderr, "%s:%d: %s.\n%.*s\n", > state->patch_input_file, linenr, err, len, line); > - free(err); > + free(err); > + } > } > > static void check_whitespace(struct apply_state *state,
diff --git a/apply.c b/apply.c index e1b4d14dba..e6df8b6ab4 100644 --- a/apply.c +++ b/apply.c @@ -1642,8 +1642,6 @@ static void record_ws_error(struct apply_state *state, int len, int linenr) { - char *err; - if (!result) return; @@ -1652,11 +1650,12 @@ static void record_ws_error(struct apply_state *state, state->squelch_whitespace_errors < state->whitespace_error) return; - err = whitespace_error_string(result); - if (state->apply_verbosity > verbosity_silent) + if (state->apply_verbosity > verbosity_silent) { + char *err = whitespace_error_string(result); fprintf(stderr, "%s:%d: %s.\n%.*s\n", state->patch_input_file, linenr, err, len, line); - free(err); + free(err); + } } static void check_whitespace(struct apply_state *state,
It does not make sense to construct an error message if we're not going to use it, especially when the process involves memory allocations that need to be freed immediately. If we know in advance that we won't use the message, not getting it slightly reduces the workload and simplifies the code a bit. Do it. Signed-off-by: Rubén Justo <rjusto@gmail.com> --- apply.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)