Re: [PATCH] Improve function dir.c:trim_trailing_spaces()

2014-06-01 Thread Jeff King
On Sat, May 31, 2014 at 08:21:31AM -0700, Pasha Bolokhov wrote: > + char *p, *last_space = NULL; > + > + for (p = buf; *p; p++) > + if (*p == ' ') { > + if (!last_space) > + last_space = p; > + } else { > +

[PATCH] Improve function dir.c:trim_trailing_spaces()

2014-05-31 Thread Pasha Bolokhov
Discard the unnecessary 'nr_spaces' variable, remove 'strlen()' and improve the 'if' structure. Switch to pointers instead of integers Slightly more rare occurrences of 'text \' with a backslash in between spaces are handled correctly. Namely, the code in 8ba87adad6 does not reset 'last_space

Re: [PATCH] Improve function dir.c:trim_trailing_spaces()

2014-05-30 Thread Junio C Hamano
Jeff King writes: > On Thu, May 29, 2014 at 02:34:33PM -0700, Pasha Bolokhov wrote: > >> > However, I doubt it makes that much of a difference in practice, so >> > unless it's measurable, I would certainly go with the version that is >> > more readable (and correct, of course). >> >> Sorry,

Re: [PATCH] Improve function dir.c:trim_trailing_spaces()

2014-05-29 Thread Jeff King
On Thu, May 29, 2014 at 02:34:33PM -0700, Pasha Bolokhov wrote: > > However, I doubt it makes that much of a difference in practice, so > > unless it's measurable, I would certainly go with the version that is > > more readable (and correct, of course). > > Sorry, just to recap, you would go

Re: [PATCH] Improve function dir.c:trim_trailing_spaces()

2014-05-29 Thread Pasha Bolokhov
On Thu, May 29, 2014 at 1:13 PM, Jeff King wrote: > On Wed, May 28, 2014 at 04:45:57PM -0700, Pasha Bolokhov wrote: > >> Move backwards from the end of the string (more efficient for >> lines which do not have trailing spaces or have just a couple). > > The original code reads the string from left

Re: [PATCH] Improve function dir.c:trim_trailing_spaces()

2014-05-29 Thread Jeff King
On Wed, May 28, 2014 at 04:45:57PM -0700, Pasha Bolokhov wrote: > Move backwards from the end of the string (more efficient for > lines which do not have trailing spaces or have just a couple). The original code reads the string from left to right. In theory, that means we could get away with not

[PATCH] Improve function dir.c:trim_trailing_spaces()

2014-05-28 Thread Pasha Bolokhov
Move backwards from the end of the string (more efficient for lines which do not have trailing spaces or have just a couple). Slightly more rare occurrences of 'text \' with a backslash in between spaces are handled correctly. Namely, the code in 8ba87adad6 does not reset 'last_space' when a b