Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs24-19fa
git_rec_nano
Commits
8db21b68
Commit
8db21b68
authored
8 years ago
by
Benno Schulenberg
Browse files
Options
Download
Email Patches
Plain Diff
tweaks: use memory on the stack instead of calling malloc() and free()
parent
cb31e45f
master
feature/match-parens
refactor/readbility
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/files.c
+1
-5
src/files.c
src/utils.c
+3
-9
src/utils.c
with
4 additions
and
14 deletions
+4
-14
src/files.c
View file @
8db21b68
...
...
@@ -2713,8 +2713,7 @@ char *input_tab(char *buf, bool allow_files, size_t *place,
char
*
mzero
,
*
glued
;
const
char
*
lastslash
=
revstrstr
(
buf
,
"/"
,
buf
+
*
place
);
size_t
lastslash_len
=
(
lastslash
==
NULL
)
?
0
:
lastslash
-
buf
+
1
;
char
*
match1
=
charalloc
(
mb_cur_max
());
char
*
match2
=
charalloc
(
mb_cur_max
());
char
match1
[
mb_cur_max
()],
match2
[
mb_cur_max
()];
int
match1_len
,
match2_len
;
/* Get the number of characters that all matches have in common. */
...
...
@@ -2735,9 +2734,6 @@ char *input_tab(char *buf, bool allow_files, size_t *place,
common_len
+=
match1_len
;
}
free
(
match1
);
free
(
match2
);
mzero
=
charalloc
(
lastslash_len
+
common_len
+
1
);
strncpy
(
mzero
,
buf
,
lastslash_len
);
...
...
This diff is collapsed.
Click to expand it.
src/utils.c
View file @
8db21b68
...
...
@@ -303,9 +303,8 @@ const char *fixbounds(const char *r)
* a separate word? That is: is it not part of a longer word?*/
bool
is_separate_word
(
size_t
position
,
size_t
length
,
const
char
*
buf
)
{
char
*
before
=
charalloc
(
mb_cur_max
()
)
,
*
after
=
charalloc
(
mb_cur_max
()
)
;
char
before
[
mb_cur_max
()
]
,
after
[
mb_cur_max
()
]
;
size_t
word_end
=
position
+
length
;
bool
retval
;
/* Get the characters before and after the word, if any. */
parse_mbchar
(
buf
+
move_mbleft
(
buf
,
position
),
before
,
NULL
);
...
...
@@ -314,13 +313,8 @@ bool is_separate_word(size_t position, size_t length, const char *buf)
/* If the word starts at the beginning of the line OR the character before
* the word isn't a letter, and if the word ends at the end of the line OR
* the character after the word isn't a letter, we have a whole word. */
retval
=
(
position
==
0
||
!
is_alpha_mbchar
(
before
))
&&
(
word_end
==
strlen
(
buf
)
||
!
is_alpha_mbchar
(
after
));
free
(
before
);
free
(
after
);
return
retval
;
return
((
position
==
0
||
!
is_alpha_mbchar
(
before
))
&&
(
buf
[
word_end
]
==
'\0'
||
!
is_alpha_mbchar
(
after
)));
}
#endif
/* !DISABLE_SPELLER */
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help