summaryrefslogtreecommitdiffstatshomepage
path: root/runtime/lua/vim/shared.lua
diff options
context:
space:
mode:
authormonkoose <pythonproof@gmail.com>2025-05-22 13:00:22 +0300
committerLewis Russell <me@lewisr.dev>2025-05-26 22:41:12 +0100
commit5e64d92411737a8fe0ea44faebf986944bfea8ea (patch)
tree8c0b72b85adba8951a7bc542225ef690905201cf /runtime/lua/vim/shared.lua
parentba1cc9e10c67e9cf8873ba67b2c0d6b8d5ecd6dd (diff)
perf(runtime): vim.trim for long only whitespace strings
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.