[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] [PATCH] chars: use memory on the stack instead of calling m
From: |
Benno Schulenberg |
Subject: |
[Nano-devel] [PATCH] chars: use memory on the stack instead of calling malloc() and free() |
Date: |
Sat, 17 Dec 2016 12:35:06 +0100 |
---
src/chars.c | 35 ++++++++++++-----------------------
1 file changed, 12 insertions(+), 23 deletions(-)
diff --git a/src/chars.c b/src/chars.c
index c93a55cc..4c1f88c9 100644
--- a/src/chars.c
+++ b/src/chars.c
@@ -208,15 +208,11 @@ bool is_word_mbchar(const char *c, bool allow_punct)
return TRUE;
if (word_chars != NULL && *word_chars != '\0') {
- bool wordforming;
- char *symbol = charalloc(MB_CUR_MAX + 1);
+ char symbol[mb_cur_max() + 1];
int symlen = parse_mbchar(c, symbol, NULL);
symbol[symlen] = '\0';
- wordforming = (strstr(word_chars, symbol) != NULL);
- free(symbol);
-
- return wordforming;
+ return (strstr(word_chars, symbol) != NULL);
}
return (allow_punct && is_punct_mbchar(c));
@@ -707,7 +703,7 @@ char *mbstrchr(const char *s, const char *c)
#ifdef ENABLE_UTF8
if (use_utf8) {
bool bad_s_mb = FALSE, bad_c_mb = FALSE;
- char *s_mb = charalloc(MB_CUR_MAX);
+ char symbol[MB_CUR_MAX];
const char *q = s;
wchar_t ws, wc;
@@ -718,9 +714,9 @@ char *mbstrchr(const char *s, const char *c)
}
while (*s != '\0') {
- int s_mb_len = parse_mbchar(s, s_mb, NULL);
+ int sym_len = parse_mbchar(s, symbol, NULL);
- if (mbtowc(&ws, s_mb, s_mb_len) < 0) {
+ if (mbtowc(&ws, symbol, sym_len) < 0) {
mbtowc_reset();
ws = (unsigned char)*s;
bad_s_mb = TRUE;
@@ -729,12 +725,10 @@ char *mbstrchr(const char *s, const char *c)
if (bad_s_mb == bad_c_mb && ws == wc)
break;
- s += s_mb_len;
- q += s_mb_len;
+ s += sym_len;
+ q += sym_len;
}
- free(s_mb);
-
if (*s == '\0')
q = NULL;
@@ -833,21 +827,16 @@ bool has_blank_mbchars(const char *s)
{
#ifdef ENABLE_UTF8
if (use_utf8) {
- bool retval = FALSE;
- char *chr_mb = charalloc(MB_CUR_MAX);
+ char symbol[MB_CUR_MAX];
for (; *s != '\0'; s += move_mbright(s, 0)) {
- parse_mbchar(s, chr_mb, NULL);
+ parse_mbchar(s, symbol, NULL);
- if (is_blank_mbchar(chr_mb)) {
- retval = TRUE;
- break;
- }
+ if (is_blank_mbchar(symbol))
+ return TRUE;
}
- free(chr_mb);
-
- return retval;
+ return FALSE;
} else
#endif
return has_blank_chars(s);
--
2.11.0
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Nano-devel] [PATCH] chars: use memory on the stack instead of calling malloc() and free(),
Benno Schulenberg <=