refactor: pos_T macros to functions (#6496)

This commit is contained in:
Felipe Oliveira Carvalho 2017-04-11 22:44:48 +02:00 committed by Justin M. Keyes
parent 1b94852ccb
commit 2d72d85b23
8 changed files with 48 additions and 21 deletions

View File

@ -15,6 +15,7 @@
#include "nvim/func_attr.h" #include "nvim/func_attr.h"
#include "nvim/indent.h" #include "nvim/indent.h"
#include "nvim/main.h" #include "nvim/main.h"
#include "nvim/mark.h"
#include "nvim/mbyte.h" #include "nvim/mbyte.h"
#include "nvim/memline.h" #include "nvim/memline.h"
#include "nvim/memory.h" #include "nvim/memory.h"
@ -1366,7 +1367,7 @@ void getvcols(win_T *wp, pos_T *pos1, pos_T *pos2, colnr_T *left,
colnr_T to1; colnr_T to1;
colnr_T to2; colnr_T to2;
if (ltp(pos1, pos2)) { if (lt(*pos1, *pos2)) {
getvvcol(wp, pos1, &from1, NULL, &to1); getvvcol(wp, pos1, &from1, NULL, &to1);
getvvcol(wp, pos2, &from2, NULL, &to2); getvvcol(wp, pos2, &from2, NULL, &to2);
} else { } else {

View File

@ -30,6 +30,7 @@
#include "nvim/if_cscope.h" #include "nvim/if_cscope.h"
#include "nvim/indent.h" #include "nvim/indent.h"
#include "nvim/main.h" #include "nvim/main.h"
#include "nvim/mark.h"
#include "nvim/mbyte.h" #include "nvim/mbyte.h"
#include "nvim/memline.h" #include "nvim/memline.h"
#include "nvim/menu.h" #include "nvim/menu.h"

View File

@ -7,6 +7,7 @@
#include "nvim/eval.h" #include "nvim/eval.h"
#include "nvim/charset.h" #include "nvim/charset.h"
#include "nvim/cursor.h" #include "nvim/cursor.h"
#include "nvim/mark.h"
#include "nvim/memline.h" #include "nvim/memline.h"
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/misc1.h" #include "nvim/misc1.h"
@ -598,7 +599,7 @@ int get_lisp_indent(void)
paren = *pos; paren = *pos;
pos = findmatch(NULL, '['); pos = findmatch(NULL, '[');
if ((pos == NULL) || ltp(pos, &paren)) { if ((pos == NULL) || lt(*pos, paren)) {
pos = &paren; pos = &paren;
} }
} }

View File

@ -10,6 +10,7 @@
#include "nvim/edit.h" #include "nvim/edit.h"
#include "nvim/indent.h" #include "nvim/indent.h"
#include "nvim/indent_c.h" #include "nvim/indent_c.h"
#include "nvim/mark.h"
#include "nvim/memline.h" #include "nvim/memline.h"
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/option.h" #include "nvim/option.h"

View File

@ -28,25 +28,6 @@
/// @return `s, sizeof(s) - 1` /// @return `s, sizeof(s) - 1`
#define S_LEN(s) (s), (sizeof(s) - 1) #define S_LEN(s) (s), (sizeof(s) - 1)
/*
* Position comparisons
*/
# define lt(a, b) (((a).lnum != (b).lnum) \
? (a).lnum < (b).lnum \
: (a).col != (b).col \
? (a).col < (b).col \
: (a).coladd < (b).coladd)
# define ltp(a, b) (((a)->lnum != (b)->lnum) \
? (a)->lnum < (b)->lnum \
: (a)->col != (b)->col \
? (a)->col < (b)->col \
: (a)->coladd < (b)->coladd)
# define equalpos(a, b) (((a).lnum == (b).lnum) && ((a).col == (b).col) && \
((a).coladd == (b).coladd))
# define clearpos(a) {(a)->lnum = 0; (a)->col = 0; (a)->coladd = 0; }
#define ltoreq(a, b) (lt(a, b) || equalpos(a, b))
/* /*
* lineempty() - return TRUE if the line is empty * lineempty() - return TRUE if the line is empty
*/ */

View File

@ -4,6 +4,7 @@
#include "nvim/macros.h" #include "nvim/macros.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/buffer_defs.h" #include "nvim/buffer_defs.h"
#include "nvim/func_attr.h"
#include "nvim/mark_defs.h" #include "nvim/mark_defs.h"
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/pos.h" #include "nvim/pos.h"
@ -75,6 +76,45 @@ static inline int mark_local_index(const char name)
: -1)))); : -1))));
} }
static inline bool lt(pos_T, pos_T) REAL_FATTR_CONST REAL_FATTR_ALWAYS_INLINE;
static inline bool equalpos(pos_T, pos_T)
REAL_FATTR_CONST REAL_FATTR_ALWAYS_INLINE;
static inline bool ltoreq(pos_T, pos_T)
REAL_FATTR_CONST REAL_FATTR_ALWAYS_INLINE;
static inline void clearpos(pos_T *) REAL_FATTR_ALWAYS_INLINE;
/// Return true if position a is before (less than) position b.
static inline bool lt(pos_T a, pos_T b)
{
if (a.lnum != b.lnum) {
return a.lnum < b.lnum;
} else if (a.col != b.col) {
return a.col < b.col;
} else {
return a.coladd < b.coladd;
}
}
/// Return true if position a and b are equal.
static inline bool equalpos(pos_T a, pos_T b)
{
return (a.lnum == b.lnum) && (a.col == b.col) && (a.coladd == b.coladd);
}
/// Return true if position a is less than or equal to b.
static inline bool ltoreq(pos_T a, pos_T b)
{
return lt(a, b) || equalpos(a, b);
}
/// Clear the pos_T structure pointed to by a.
static inline void clearpos(pos_T *a)
{
a->lnum = 0;
a->col = 0;
a->coladd = 0;
}
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "mark.h.generated.h" # include "mark.h.generated.h"
#endif #endif

View File

@ -102,6 +102,7 @@
#include "nvim/indent.h" #include "nvim/indent.h"
#include "nvim/getchar.h" #include "nvim/getchar.h"
#include "nvim/main.h" #include "nvim/main.h"
#include "nvim/mark.h"
#include "nvim/mbyte.h" #include "nvim/mbyte.h"
#include "nvim/memline.h" #include "nvim/memline.h"
#include "nvim/memory.h" #include "nvim/memory.h"

View File

@ -92,6 +92,7 @@
#include "nvim/func_attr.h" #include "nvim/func_attr.h"
#include "nvim/getchar.h" #include "nvim/getchar.h"
#include "nvim/hashtab.h" #include "nvim/hashtab.h"
#include "nvim/mark.h"
#include "nvim/mbyte.h" #include "nvim/mbyte.h"
#include "nvim/memline.h" #include "nvim/memline.h"
#include "nvim/memory.h" #include "nvim/memory.h"