Hello, I would like help optimizing my custom filesystem library, more precisely the 'readLine' function. It takes ages to read one line, and I think it's because it's badly optimized.
Here is the code:
local line = ""
local data = nil
repeat
local data = fs.read(handle, 1) -- Reads 1 character
if data and data ~= "\n" then
line = line .. (data or "")
else
data = nil
end
until not data
return line ~= "" and line or nil
If possible, it would be nice to help me upgrade the code, as at the end you see it should return nil instead of a text, it's my bad code and in the final return text, there is sometimes a weird icon at the end (the \n char when printing the result).
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
Hello, I would like help optimizing my custom filesystem library, more precisely the 'readLine' function.
It takes ages to read one line, and I think it's because it's badly optimized.
Here is the code:
If possible, it would be nice to help me upgrade the code, as at the end you see it should return nil instead of a text, it's my bad code and in the final return text, there is sometimes a weird icon at the end (the \n char when printing the result).
Thanks from advance.
Link to post
Share on other sites