From 2a20f1d816299ee7bb65e6f9df706b65f7e4889a Mon Sep 17 00:00:00 2001 From: hood Date: Wed, 4 Nov 2026 22:10:54 +0100 Subject: [PATCH] perf(str): use string.find in str.oneline --- lua/cmp/utils/str.lua | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lua/cmp/utils/str.lua b/lua/cmp/utils/str.lua index 3b7219803..74dca3eca 100644 --- a/lua/cmp/utils/str.lua +++ b/lua/cmp/utils/str.lua @@ -16,8 +16,6 @@ INVALIDS[string.byte('\t')] = true INVALIDS[string.byte('\n')] = true INVALIDS[string.byte('\r')] = true -local NR_BYTE = string.byte('\n') - local PAIRS = {} PAIRS[string.byte('<')] = string.byte('>') PAIRS[string.byte('[')] = string.byte(']') @@ -159,10 +157,9 @@ end ---@param text string ---@return string str.oneline = function(text) - for i = 1, #text do - if string.byte(text, i) == NR_BYTE then - return string.sub(text, 1, i - 1) - end + local i = string.find(text, '\n', 1, true) + if i then + return string.sub(text, 1, i - 1) end return text end