mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-30 19:13:53 +01:00
shaved some milliseconds off split
This commit is contained in:
parent
6e3b9d99e9
commit
af07a158a8
@ -42,13 +42,13 @@ function worldeditadditions.gsplit(text, pattern, plain)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Split a string into substrings separated by a pattern.
|
--- Split a string into substrings separated by a pattern. -- Deprecated
|
||||||
-- @param text string The string to iterate over
|
-- @param text string The string to iterate over
|
||||||
-- @param pattern string The separator pattern
|
-- @param pattern string The separator pattern
|
||||||
-- @param plain boolean If true (or truthy), pattern is interpreted as a
|
-- @param plain boolean If true (or truthy), pattern is interpreted as a
|
||||||
-- plain string, not a Lua pattern
|
-- plain string, not a Lua pattern
|
||||||
-- @returns table A sequence table containing the substrings
|
-- @returns table A sequence table containing the substrings
|
||||||
function worldeditadditions.split(text, pattern, plain)
|
function worldeditadditions.dsplit(text, pattern, plain)
|
||||||
local ret = {}
|
local ret = {}
|
||||||
for match in worldeditadditions.gsplit(text, pattern, plain) do
|
for match in worldeditadditions.gsplit(text, pattern, plain) do
|
||||||
table.insert(ret, match)
|
table.insert(ret, match)
|
||||||
@ -62,15 +62,24 @@ end
|
|||||||
-- @param plain boolean If true (or truthy), pattern is interpreted as a
|
-- @param plain boolean If true (or truthy), pattern is interpreted as a
|
||||||
-- plain string, not a Lua pattern
|
-- plain string, not a Lua pattern
|
||||||
-- @returns table A sequence table containing the substrings
|
-- @returns table A sequence table containing the substrings
|
||||||
function worldeditadditions.fsplit (str,dlm,plain)
|
function worldeditadditions.split (str,dlm,plain)
|
||||||
local pos, ins = 0, 0
|
local pos, ret = 0, {}
|
||||||
local ret = {}
|
local ins, i = str:find(dlm,pos,plain)
|
||||||
repeat
|
-- if plain shaves off some time in the while statement
|
||||||
ins = str:find(dlm,pos,plain)
|
if plain then
|
||||||
|
while ins do
|
||||||
table.insert(ret,str:sub(pos,ins - 1))
|
table.insert(ret,str:sub(pos,ins - 1))
|
||||||
pos = ins + #dlm
|
pos = ins + #dlm
|
||||||
until not str:find(dlm,pos,plain)
|
ins = str:find(dlm,pos,true)
|
||||||
print(pos..","..#str)
|
end
|
||||||
|
else
|
||||||
|
while ins do
|
||||||
|
table.insert(ret,str:sub(pos,ins - 1))
|
||||||
|
pos = i + 1
|
||||||
|
ins, i = str:find(dlm,pos)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- print(pos..","..#str)
|
||||||
if str:sub(pos,#str) ~= "" then
|
if str:sub(pos,#str) ~= "" then
|
||||||
table.insert(ret,str:sub(pos,#str))
|
table.insert(ret,str:sub(pos,#str))
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user