summaryrefslogtreecommitdiffstatshomepage
path: root/runtime/lua/vim/shared.lua
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua/vim/shared.lua')
-rw-r--r--runtime/lua/vim/shared.lua4
1 files changed, 3 insertions, 1 deletions
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua
index fa66e18ac4..73b7408118 100644
--- a/runtime/lua/vim/shared.lua
+++ b/runtime/lua/vim/shared.lua
@@ -801,7 +801,9 @@ end
---@return string String with whitespace removed from its beginning and end
function vim.trim(s)
vim.validate('s', s, 'string')
- return s:match('^%s*(.*%S)') or ''
+ -- `s:match('^%s*(.*%S)')` is slow for long whitespace strings,
+ -- so we are forced to split it into two parts to prevent this
+ return s:gsub('^%s+', ''):match('^.*%S') or ''
end
--- Escapes magic chars in |lua-pattern|s.