Merge pull request #18091 from dundargoc/refactor/pure-attribute

refactor: add pure attribute to pure functions
This commit is contained in:
bfredl
2022-04-18 21:40:14 +02:00
committed by GitHub
8 changed files with 21 additions and 0 deletions

View File

@@ -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 one First character.
/// @param two Character just after "one". /// @param two Character just after "one".
bool arabic_combine(int one, int two) bool arabic_combine(int one, int two)
FUNC_ATTR_PURE
{ {
if (one == a_LAM) { if (one == a_LAM) {
return arabic_maycombine(two); 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 /// Check whether we are dealing with a character that could be regarded as an
/// Arabic combining character, need to check the character before this. /// Arabic combining character, need to check the character before this.
bool arabic_maycombine(int two) bool arabic_maycombine(int two)
FUNC_ATTR_PURE
{ {
if (p_arshape && !p_tbidi) { if (p_arshape && !p_tbidi) {
return two == a_ALEF_MADDA return two == a_ALEF_MADDA

View File

@@ -379,6 +379,7 @@ static void au_cleanup(void)
// Get the first AutoPat for a particular event. // Get the first AutoPat for a particular event.
AutoPat *au_get_autopat_for_event(event_T event) AutoPat *au_get_autopat_for_event(event_T event)
FUNC_ATTR_PURE
{ {
return first_autopat[(int)event]; 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) size_t aucmd_pattern_length(char_u *pat)
FUNC_ATTR_PURE
{ {
if (*pat == NUL) { if (*pat == NUL) {
return 0; 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) char_u *aucmd_next_pattern(char_u *pat, size_t patlen)
FUNC_ATTR_PURE
{ {
pat = pat + patlen; pat = pat + patlen;
if (*pat == ',') { if (*pat == ',') {
@@ -2383,6 +2386,7 @@ theend:
// Checks if a pattern is buflocal // Checks if a pattern is buflocal
bool aupat_is_buflocal(char_u *pat, int patlen) bool aupat_is_buflocal(char_u *pat, int patlen)
FUNC_ATTR_PURE
{ {
return patlen >= 8 return patlen >= 8
&& STRNCMP(pat, "<buffer", 7) == 0 && 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) char *aucmd_exec_to_string(AutoCmd *ac, AucmdExecutable acc)
FUNC_ATTR_PURE
{ {
switch (acc.type) { switch (acc.type) {
case CALLABLE_EX: case CALLABLE_EX:
@@ -2542,6 +2547,7 @@ AucmdExecutable aucmd_exec_copy(AucmdExecutable src)
} }
bool aucmd_exec_is_deleted(AucmdExecutable acc) bool aucmd_exec_is_deleted(AucmdExecutable acc)
FUNC_ATTR_PURE
{ {
switch (acc.type) { switch (acc.type) {
case CALLABLE_EX: case CALLABLE_EX:
@@ -2556,6 +2562,7 @@ bool aucmd_exec_is_deleted(AucmdExecutable acc)
} }
bool au_event_is_empty(event_T event) bool au_event_is_empty(event_T event)
FUNC_ATTR_PURE
{ {
return first_autopat[event] == NULL; return first_autopat[event] == NULL;
} }

View File

@@ -84,6 +84,7 @@ bool buf_updates_register(buf_T *buf, uint64_t channel_id, BufUpdateCallbacks cb
} }
bool buf_updates_active(buf_T *buf) bool buf_updates_active(buf_T *buf)
FUNC_ATTR_PURE
{ {
return kv_size(buf->update_channels) || kv_size(buf->update_callbacks); return kv_size(buf->update_channels) || kv_size(buf->update_callbacks);
} }

View File

@@ -33,6 +33,7 @@ void ctx_free_all(void)
/// Returns the size of the context stack. /// Returns the size of the context stack.
size_t ctx_size(void) size_t ctx_size(void)
FUNC_ATTR_PURE
{ {
return kv_size(ctx_stack); 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 /// Returns pointer to Context object with given zero-based index from the top
/// of context stack or NULL if index is out of bounds. /// of context stack or NULL if index is out of bounds.
Context *ctx_get(size_t index) Context *ctx_get(size_t index)
FUNC_ATTR_PURE
{ {
if (index < kv_size(ctx_stack)) { if (index < kv_size(ctx_stack)) {
return &kv_Z(ctx_stack, index); return &kv_Z(ctx_stack, index);

View File

@@ -277,6 +277,7 @@ char *parse_shape_opt(int what)
/// ///
/// @param exclusive If 'selection' option is "exclusive". /// @param exclusive If 'selection' option is "exclusive".
bool cursor_is_block_during_visual(bool exclusive) bool cursor_is_block_during_visual(bool exclusive)
FUNC_ATTR_PURE
{ {
int mode_idx = exclusive ? SHAPE_IDX_VE : SHAPE_IDX_V; int mode_idx = exclusive ? SHAPE_IDX_VE : SHAPE_IDX_V;
return (SHAPE_BLOCK == shape_table[mode_idx].shape 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. /// Check if a syntax id is used as a cursor style.
bool cursor_mode_uses_syn_id(int syn_id) bool cursor_mode_uses_syn_id(int syn_id)
FUNC_ATTR_PURE
{ {
if (*p_guicursor == NUL) { if (*p_guicursor == NUL) {
return false; 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. /// Return the index into shape_table[] for the current mode.
int cursor_get_mode_idx(void) int cursor_get_mode_idx(void)
FUNC_ATTR_PURE
{ {
if (State == SHOWMATCH) { if (State == SHOWMATCH) {
return SHAPE_IDX_SM; return SHAPE_IDX_SM;

View File

@@ -883,6 +883,7 @@ theend:
/// diff will be used anyway. /// diff will be used anyway.
/// ///
int diff_internal(void) int diff_internal(void)
FUNC_ATTR_PURE
{ {
return (diff_flags & DIFF_INTERNAL) != 0 && *p_dex == NUL; return (diff_flags & DIFF_INTERNAL) != 0 && *p_dex == NUL;
} }
@@ -2250,6 +2251,7 @@ bool diffopt_horizontal(void)
// Return true if 'diffopt' contains "hiddenoff". // Return true if 'diffopt' contains "hiddenoff".
bool diffopt_hiddenoff(void) bool diffopt_hiddenoff(void)
FUNC_ATTR_PURE
{ {
return (diff_flags & DIFF_HIDDEN_OFF) != 0; return (diff_flags & DIFF_HIDDEN_OFF) != 0;
} }

View File

@@ -1551,6 +1551,7 @@ int get_digraph(bool cmdline)
/// @return If no match, return "char2". If "meta_char" is true and "char1" /// @return If no match, return "char2". If "meta_char" is true and "char1"
// is a space, return "char2" | 0x80. // is a space, return "char2" | 0x80.
static int getexactdigraph(int char1, int char2, bool meta_char) static int getexactdigraph(int char1, int char2, bool meta_char)
FUNC_ATTR_PURE
{ {
int retval = 0; int retval = 0;
@@ -1601,6 +1602,7 @@ static int getexactdigraph(int char1, int char2, bool meta_char)
/// ///
/// @return The digraph. /// @return The digraph.
int digraph_get(int char1, int char2, bool meta_char) int digraph_get(int char1, int char2, bool meta_char)
FUNC_ATTR_PURE
{ {
int retval; int retval;

View File

@@ -2604,6 +2604,7 @@ char_u *getexline(int c, void *cookie, int indent, bool do_concat)
} }
bool cmdline_overstrike(void) bool cmdline_overstrike(void)
FUNC_ATTR_PURE
{ {
return ccline.overstrike; return ccline.overstrike;
} }
@@ -2611,6 +2612,7 @@ bool cmdline_overstrike(void)
/// Return true if the cursor is at the end of the cmdline. /// Return true if the cursor is at the end of the cmdline.
bool cmdline_at_end(void) bool cmdline_at_end(void)
FUNC_ATTR_PURE
{ {
return (ccline.cmdpos >= ccline.cmdlen); return (ccline.cmdpos >= ccline.cmdlen);
} }