aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDundar Göc <gocdundar@gmail.com>2022-04-11 18:29:48 +0200
committerDundar Göc <gocdundar@gmail.com>2022-04-13 22:12:12 +0200
commit0fb571e3b5043f136f2394d84b942b8c93fdde45 (patch)
tree897846d0a34979ccf7db46c53926aafaea437f9c
parent9a357043333cee38846a7a9a764cdae96d0856fd (diff)
downloadrneovim-0fb571e3b5043f136f2394d84b942b8c93fdde45.tar.gz
rneovim-0fb571e3b5043f136f2394d84b942b8c93fdde45.tar.bz2
rneovim-0fb571e3b5043f136f2394d84b942b8c93fdde45.zip
refactor: add pure attribute to pure functions
This will allow compilers that support the pure attribute to make further optimizations to functions.
-rw-r--r--src/nvim/arabic.c2
-rw-r--r--src/nvim/autocmd.c7
-rw-r--r--src/nvim/buffer_updates.c1
-rw-r--r--src/nvim/context.c2
-rw-r--r--src/nvim/cursor_shape.c3
-rw-r--r--src/nvim/diff.c2
-rw-r--r--src/nvim/digraph.c2
-rw-r--r--src/nvim/ex_getln.c2
8 files changed, 21 insertions, 0 deletions
diff --git a/src/nvim/arabic.c b/src/nvim/arabic.c
index 5dcc3d3d0d..db78e0e68f 100644
--- a/src/nvim/arabic.c
+++ b/src/nvim/arabic.c
@@ -974,6 +974,7 @@ int arabic_shape(int c, int *ccp, int *c1p, int prev_c, int prev_c1, int next_c)
/// @param one First character.
/// @param two Character just after "one".
bool arabic_combine(int one, int two)
+ FUNC_ATTR_PURE
{
if (one == a_LAM) {
return arabic_maycombine(two);
@@ -984,6 +985,7 @@ bool arabic_combine(int one, int two)
/// Check whether we are dealing with a character that could be regarded as an
/// Arabic combining character, need to check the character before this.
bool arabic_maycombine(int two)
+ FUNC_ATTR_PURE
{
if (p_arshape && !p_tbidi) {
return two == a_ALEF_MADDA
diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c
index 1b146f82c6..77d4115b59 100644
--- a/src/nvim/autocmd.c
+++ b/src/nvim/autocmd.c
@@ -379,6 +379,7 @@ static void au_cleanup(void)
// Get the first AutoPat for a particular event.
AutoPat *au_get_autopat_for_event(event_T event)
+ FUNC_ATTR_PURE
{
return first_autopat[(int)event];
}
@@ -1143,6 +1144,7 @@ int autocmd_register(int64_t id, event_T event, char_u *pat, int patlen, int gro
}
size_t aucmd_pattern_length(char_u *pat)
+ FUNC_ATTR_PURE
{
if (*pat == NUL) {
return 0;
@@ -1175,6 +1177,7 @@ size_t aucmd_pattern_length(char_u *pat)
}
char_u *aucmd_next_pattern(char_u *pat, size_t patlen)
+ FUNC_ATTR_PURE
{
pat = pat + patlen;
if (*pat == ',') {
@@ -2383,6 +2386,7 @@ theend:
// Checks if a pattern is buflocal
bool aupat_is_buflocal(char_u *pat, int patlen)
+ FUNC_ATTR_PURE
{
return patlen >= 8
&& STRNCMP(pat, "<buffer", 7) == 0
@@ -2492,6 +2496,7 @@ char *aucmd_exec_default_desc(AucmdExecutable acc)
}
char *aucmd_exec_to_string(AutoCmd *ac, AucmdExecutable acc)
+ FUNC_ATTR_PURE
{
switch (acc.type) {
case CALLABLE_EX:
@@ -2542,6 +2547,7 @@ AucmdExecutable aucmd_exec_copy(AucmdExecutable src)
}
bool aucmd_exec_is_deleted(AucmdExecutable acc)
+ FUNC_ATTR_PURE
{
switch (acc.type) {
case CALLABLE_EX:
@@ -2556,6 +2562,7 @@ bool aucmd_exec_is_deleted(AucmdExecutable acc)
}
bool au_event_is_empty(event_T event)
+ FUNC_ATTR_PURE
{
return first_autopat[event] == NULL;
}
diff --git a/src/nvim/buffer_updates.c b/src/nvim/buffer_updates.c
index ee1b7ebc95..3e2d04b3a2 100644
--- a/src/nvim/buffer_updates.c
+++ b/src/nvim/buffer_updates.c
@@ -84,6 +84,7 @@ bool buf_updates_register(buf_T *buf, uint64_t channel_id, BufUpdateCallbacks cb
}
bool buf_updates_active(buf_T *buf)
+ FUNC_ATTR_PURE
{
return kv_size(buf->update_channels) || kv_size(buf->update_callbacks);
}
diff --git a/src/nvim/context.c b/src/nvim/context.c
index 9434b4e0ea..c30a05a3c8 100644
--- a/src/nvim/context.c
+++ b/src/nvim/context.c
@@ -33,6 +33,7 @@ void ctx_free_all(void)
/// Returns the size of the context stack.
size_t ctx_size(void)
+ FUNC_ATTR_PURE
{
return kv_size(ctx_stack);
}
@@ -40,6 +41,7 @@ size_t ctx_size(void)
/// Returns pointer to Context object with given zero-based index from the top
/// of context stack or NULL if index is out of bounds.
Context *ctx_get(size_t index)
+ FUNC_ATTR_PURE
{
if (index < kv_size(ctx_stack)) {
return &kv_Z(ctx_stack, index);
diff --git a/src/nvim/cursor_shape.c b/src/nvim/cursor_shape.c
index 0e4a4bcfb0..73adff6579 100644
--- a/src/nvim/cursor_shape.c
+++ b/src/nvim/cursor_shape.c
@@ -277,6 +277,7 @@ char *parse_shape_opt(int what)
///
/// @param exclusive If 'selection' option is "exclusive".
bool cursor_is_block_during_visual(bool exclusive)
+ FUNC_ATTR_PURE
{
int mode_idx = exclusive ? SHAPE_IDX_VE : SHAPE_IDX_V;
return (SHAPE_BLOCK == shape_table[mode_idx].shape
@@ -300,6 +301,7 @@ int cursor_mode_str2int(const char *mode)
/// Check if a syntax id is used as a cursor style.
bool cursor_mode_uses_syn_id(int syn_id)
+ FUNC_ATTR_PURE
{
if (*p_guicursor == NUL) {
return false;
@@ -316,6 +318,7 @@ bool cursor_mode_uses_syn_id(int syn_id)
/// Return the index into shape_table[] for the current mode.
int cursor_get_mode_idx(void)
+ FUNC_ATTR_PURE
{
if (State == SHOWMATCH) {
return SHAPE_IDX_SM;
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index 0b55fb877c..9e8fa2e62d 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -883,6 +883,7 @@ theend:
/// diff will be used anyway.
///
int diff_internal(void)
+ FUNC_ATTR_PURE
{
return (diff_flags & DIFF_INTERNAL) != 0 && *p_dex == NUL;
}
@@ -2250,6 +2251,7 @@ bool diffopt_horizontal(void)
// Return true if 'diffopt' contains "hiddenoff".
bool diffopt_hiddenoff(void)
+ FUNC_ATTR_PURE
{
return (diff_flags & DIFF_HIDDEN_OFF) != 0;
}
diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c
index 083c868607..0e148543aa 100644
--- a/src/nvim/digraph.c
+++ b/src/nvim/digraph.c
@@ -1551,6 +1551,7 @@ int get_digraph(bool cmdline)
/// @return If no match, return "char2". If "meta_char" is true and "char1"
// is a space, return "char2" | 0x80.
static int getexactdigraph(int char1, int char2, bool meta_char)
+ FUNC_ATTR_PURE
{
int retval = 0;
@@ -1601,6 +1602,7 @@ static int getexactdigraph(int char1, int char2, bool meta_char)
///
/// @return The digraph.
int digraph_get(int char1, int char2, bool meta_char)
+ FUNC_ATTR_PURE
{
int retval;
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index a7c0b06050..33e71115a4 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -2604,6 +2604,7 @@ char_u *getexline(int c, void *cookie, int indent, bool do_concat)
}
bool cmdline_overstrike(void)
+ FUNC_ATTR_PURE
{
return ccline.overstrike;
}
@@ -2611,6 +2612,7 @@ bool cmdline_overstrike(void)
/// Return true if the cursor is at the end of the cmdline.
bool cmdline_at_end(void)
+ FUNC_ATTR_PURE
{
return (ccline.cmdpos >= ccline.cmdlen);
}