aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/regexp.c
diff options
context:
space:
mode:
authorJames McCoy <jamessan@jamessan.com>2017-09-22 10:07:35 -0400
committerJames McCoy <jamessan@jamessan.com>2017-09-23 07:42:21 -0400
commit094bc39d017df34796bf92f50f5261d6ac33e83d (patch)
treeecf08d95a7c9459fa5a79202d85e6666c3f5ee88 /src/nvim/regexp.c
parent6d471636ee3bcdea7ac0c083b73f050eb720b394 (diff)
downloadrneovim-094bc39d017df34796bf92f50f5261d6ac33e83d.tar.gz
rneovim-094bc39d017df34796bf92f50f5261d6ac33e83d.tar.bz2
rneovim-094bc39d017df34796bf92f50f5261d6ac33e83d.zip
Move definition of cstrchr above the functions which call it
Functions with FUNC_ATTR_ALWAYS_INLINE need to be defined before they are called to work around bugs with some compiler versions. When the body is after the use of the function, compilation will fail with /home/niko/build/neovim/src/nvim/regexp.c: In function 'regmatch': /home/niko/build/neovim/build/src/nvim/auto/regexp.c.generated.h:77: sorry, unimplemented: inlining failed in call to 'cstrchr': function body not available /home/niko/build/neovim/src/nvim/regexp.c:4193: sorry, unimplemented: called from here
Diffstat (limited to 'src/nvim/regexp.c')
-rw-r--r--src/nvim/regexp.c77
1 files changed, 41 insertions, 36 deletions
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c
index 847b2f273e..ae611a0005 100644
--- a/src/nvim/regexp.c
+++ b/src/nvim/regexp.c
@@ -3316,6 +3316,47 @@ bt_regexec_nl (
return (int)r;
}
+/// Wrapper around strchr which accounts for case-insensitive searches and
+/// non-ASCII characters.
+///
+/// This function is used a lot for simple searches, keep it fast!
+///
+/// @param s string to search
+/// @param c character to find in @a s
+///
+/// @return NULL if no match, otherwise pointer to the position in @a s
+static inline char_u *cstrchr(const char_u *const s, const int c)
+ FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
+ FUNC_ATTR_ALWAYS_INLINE
+{
+ if (!rex.reg_ic) {
+ return vim_strchr(s, c);
+ }
+
+ // Use folded case for UTF-8, slow! For ASCII use libc strpbrk which is
+ // expected to be highly optimized.
+ if (c > 0x80) {
+ const int folded_c = utf_fold(c);
+ for (const char_u *p = s; *p != NUL; p += utfc_ptr2len(p)) {
+ if (utf_fold(utf_ptr2char(p)) == folded_c) {
+ return (char_u *)p;
+ }
+ }
+ return NULL;
+ }
+
+ int cc;
+ if (ASCII_ISUPPER(c)) {
+ cc = TOLOWER_ASC(c);
+ } else if (ASCII_ISLOWER(c)) {
+ cc = TOUPPER_ASC(c);
+ } else {
+ return vim_strchr(s, c);
+ }
+
+ char tofind[] = { (char)c, (char)cc, NUL };
+ return (char_u *)strpbrk((const char *)s, tofind);
+}
/// Matches a regexp against multiple lines.
/// "rmp->regprog" is a compiled regexp as returned by vim_regcomp().
@@ -6320,42 +6361,6 @@ static int cstrncmp(char_u *s1, char_u *s2, int *n)
return result;
}
-/*
- * cstrchr: This function is used a lot for simple searches, keep it fast!
- */
-static inline char_u *cstrchr(const char_u *const s, const int c)
- FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
- FUNC_ATTR_ALWAYS_INLINE
-{
- if (!rex.reg_ic) {
- return vim_strchr(s, c);
- }
-
- // Use folded case for UTF-8, slow! For ASCII use libc strpbrk which is
- // expected to be highly optimized.
- if (c > 0x80) {
- const int folded_c = utf_fold(c);
- for (const char_u *p = s; *p != NUL; p += utfc_ptr2len(p)) {
- if (utf_fold(utf_ptr2char(p)) == folded_c) {
- return (char_u *)p;
- }
- }
- return NULL;
- }
-
- int cc;
- if (ASCII_ISUPPER(c)) {
- cc = TOLOWER_ASC(c);
- } else if (ASCII_ISLOWER(c)) {
- cc = TOUPPER_ASC(c);
- } else {
- return vim_strchr(s, c);
- }
-
- char tofind[] = { (char)c, (char)cc, NUL };
- return (char_u *)strpbrk((const char *)s, tofind);
-}
-
/***************************************************************
* regsub stuff *
***************************************************************/