avoid some unnecessary allocations
To find the first word we currently strip _all_ Lua comments. This is really wasteful for large definitions. At least avoid all these allocations if the first word is not a comment.
This commit is contained in:
parent
5cac6d8584
commit
f23ed15fd9
9
live.lua
9
live.lua
|
@ -230,11 +230,18 @@ function live.run(buf)
|
|||
end
|
||||
|
||||
function live.get_cmd_from_buffer(buf)
|
||||
-- return the first word
|
||||
return buf:match('^%s*(%S+)')
|
||||
end
|
||||
|
||||
function live.get_definition_name_from_buffer(buf)
|
||||
return buf:gsub('%-%-[^\n]*', ''):match('^%s*(%S+)')
|
||||
-- Return the first word, after skipping Lua comments.
|
||||
if not buf:match('^%s*%-%-') then
|
||||
return buf:match('^%s*(%S+)') -- avoid unnecessary allocations
|
||||
end
|
||||
-- wastefully strip out comments everywhere, not just at the start
|
||||
buf = buf:gsub('%-%-[^\n]*', '') -- line comments
|
||||
return buf:match('^%s*(%S+)')
|
||||
end
|
||||
|
||||
function live.get_binding(name)
|
||||
|
|
Loading…
Reference in New Issue
Block a user