commit 8582e4a6b93670012015870593fc3ee36c1ed445
parent 9b34d0a4fb49412649285939014f0f2f783d90d9
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sat, 8 Jun 2019 13:34:15 +0200
tweaks: don't bother keeping track of whether a squeezed line has shrunk
When squeezing excess spaces from a line has proved unsuccessful, we
have already copied all of its data, so it hardly makes a difference
whether we free the old or the new data. Choose to free always the
old data, so that we can simplify things.
Diffstat:
1 file changed, 8 insertions(+), 20 deletions(-)
diff --git a/src/text.c b/src/text.c
@@ -1603,7 +1603,6 @@ size_t indent_length(const char *line)
void squeeze(linestruct *line, size_t skip)
{
char *from, *to, *newdata;
- size_t shrunk = 0;
int charlen;
newdata = charalloc(strlen(line->data) + 1);
@@ -1618,11 +1617,8 @@ void squeeze(linestruct *line, size_t skip)
from += parse_mbchar(from, NULL, NULL);
*(to++) = ' ';
- while (*from != '\0' && is_blank_mbchar(from)) {
- charlen = parse_mbchar(from, NULL, NULL);
- from += charlen;
- shrunk += charlen;
- }
+ while (*from != '\0' && is_blank_mbchar(from))
+ from += parse_mbchar(from, NULL, NULL);
/* If this character is punctuation, then copy it plus a possible
* bracket, and change at most two of subsequent blanks to spaces,
* and pass over all blanks after these. */
@@ -1652,11 +1648,8 @@ void squeeze(linestruct *line, size_t skip)
*(to++) = ' ';
}
- while (*from != '\0' && is_blank_mbchar(from)) {
- charlen = parse_mbchar(from, NULL, NULL);
- from += charlen;
- shrunk += charlen;
- }
+ while (*from != '\0' && is_blank_mbchar(from))
+ from += parse_mbchar(from, NULL, NULL);
/* Leave unchanged anything that is neither blank nor punctuation. */
} else {
charlen = parse_mbchar(from, NULL, NULL);
@@ -1669,17 +1662,12 @@ void squeeze(linestruct *line, size_t skip)
}
/* If there are spaces at the end of the line, remove them. */
- while (to > newdata + skip && *(to - 1) == ' ') {
+ while (to > newdata + skip && *(to - 1) == ' ')
to--;
- shrunk++;
- }
- if (shrunk > 0) {
- *to = '\0';
- free(line->data);
- line->data = newdata;
- } else
- free(newdata);
+ *to = '\0';
+ free(line->data);
+ line->data = newdata;
}
/* Return the length of the quote part of the given line. The "quote part"