diff options
author | Nicolas Hillegeer <nicolas@hillegeer.com> | 2014-04-28 21:07:03 +0200 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-04-29 09:29:10 -0300 |
commit | eea98c4d3b695b9ca95db7ac33231e62cdf88ceb (patch) | |
tree | c48634c80de748e8260548db05a3606dddcd2770 /src | |
parent | 767f0fae0b2f981b4563c5b5e2ffdd2b8ed8e27b (diff) | |
download | rneovim-eea98c4d3b695b9ca95db7ac33231e62cdf88ceb.tar.gz rneovim-eea98c4d3b695b9ca95db7ac33231e62cdf88ceb.tar.bz2 rneovim-eea98c4d3b695b9ca95db7ac33231e62cdf88ceb.zip |
garray: refactor and optimize ga_concat
I've checked all uses of ga_concat in the codebase:
- ex_cmds2.c
- ex_getln.c
- eval.c
- message.c
- regexp-nfa.c
- term.c
- spell.c
None of them concats the garray with itself. This makes it safe to use the
faster memcpy() instead of memmove(). This change was also documented.
Diffstat (limited to 'src')
-rw-r--r-- | src/garray.c | 12 | ||||
-rw-r--r-- | src/garray.h | 2 |
2 files changed, 9 insertions, 5 deletions
diff --git a/src/garray.c b/src/garray.c index 8871a8637c..1d9195d7ab 100644 --- a/src/garray.c +++ b/src/garray.c @@ -142,15 +142,19 @@ char_u* ga_concat_strings(const garray_T *gap) } /// Concatenate a string to a growarray which contains characters. -/// Note: Does NOT copy the NUL at the end! +/// +/// WARNING: +/// - Does NOT copy the NUL at the end! +/// - The parameter may not overlap with the growing array /// /// @param gap /// @param s -void ga_concat(garray_T *gap, char_u *s) +void ga_concat(garray_T *gap, const char_u *restrict s) { - int len = (int)STRLEN(s); + int len = (int)strlen((char *) s); ga_grow(gap, len); - memmove((char *)gap->ga_data + gap->ga_len, s, (size_t)len); + char *data = gap->ga_data; + memcpy(data + gap->ga_len, s, (size_t) len); gap->ga_len += len; } diff --git a/src/garray.h b/src/garray.h index 2c7bc2f375..2a0deacef7 100644 --- a/src/garray.h +++ b/src/garray.h @@ -24,7 +24,7 @@ char_u *ga_concat_strings_sep(const garray_T *gap, const char *sep) FUNC_ATTR_NONNULL_RET; char_u *ga_concat_strings(const garray_T *gap) FUNC_ATTR_NONNULL_RET; void ga_remove_duplicate_strings(garray_T *gap); -void ga_concat(garray_T *gap, char_u *s); +void ga_concat(garray_T *gap, const char_u *restrict s); void ga_append(garray_T *gap, char c); void append_ga_line(garray_T *gap); |