From 516b173780e39de3ce1e4525f0a8f0ff250c992b Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 13 Jul 2023 10:17:19 +0100 Subject: perf(rtp): reduce rtp scans (#24191) * perf(rtp): reduce rtp scans Problem: Scanning the filesystem is expensive and particularly affects startuptime. Solution: Reduce the amount of redundant directory scans by relying less on glob patterns and handle vim and lua sourcing lower down. --- src/nvim/strings.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/nvim/strings.c') diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 6fe2fd8ff3..52a803a3cc 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -436,6 +436,25 @@ char *vim_strchr(const char *const string, const int c) } } +/// Test if "str" ends with "suffix" +/// +/// @param[in] str +/// @param[in] suffix to match +/// +/// @return [allocated] Copy of the string. +bool str_ends_with(const char *str, const char *suffix) +{ + if (!str || !suffix) { + return false; + } + size_t lenstr = strlen(str); + size_t lensuffix = strlen(suffix); + if (lensuffix > lenstr) { + return false; + } + return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0; +} + // Sort an array of strings. #ifdef INCLUDE_GENERATED_DECLARATIONS -- cgit