diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-05-14 14:45:38 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-05-14 14:45:45 -0700 |
| commit | 7410e42bc00c8438884a475ccf8a9e07b73eaec3 (patch) | |
| tree | fc8bec6c4c2a885aceb75fc784bdc4d07cd5392f /code_obj.lua | |
| parent | 95ee15982bb021e94a4976741a0bcdfe5f5d6992 (diff) | |
Minor optimizations.
Diffstat (limited to 'code_obj.lua')
| -rw-r--r-- | code_obj.lua | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/code_obj.lua b/code_obj.lua index c563a91..4c9eac0 100644 --- a/code_obj.lua +++ b/code_obj.lua @@ -151,38 +151,37 @@ do _class_0 = setmetatable({ __init = function(self, source, ...) self.source = source - self.indents = { } self.bits = { ... } - if type(self.source) == 'string' then - local filename, start, stop = self.source:match("^(.-)%[(%d+):(%d+)%]$") - if not (filename) then - filename, start = self.source:match("^(.-)%[(%d+)%]$") - end - if start or stop then - self.source = Source(filename, tonumber(start), tonumber(stop)) - else - self.source = Source(self.source, 1, #tostring(self) + 1) - end - end - assert(self.source == nil or Source:is_instance(self.source)) - local indent = 0 + local indent, indents = 0, { } + local match = string.match for i, b in ipairs(self.bits) do - assert(not Source:is_instance(b)) if type(b) == 'string' then do - local spaces = b:match("\n([ ]*)[^\n]*$") + local spaces = match(b, "\n([ ]*)[^\n]*$") if spaces then indent = #spaces end end elseif indent ~= 0 then - self.indents[i] = indent + indents[i] = indent end end self.current_indent = indent + self.indents = indents self.__str = nil + if type(self.source) == 'string' then + local filename, start, stop = self.source:match("^(.-)%[(%d+):(%d+)%]$") + if not (filename) then + filename, start = self.source:match("^(.-)%[(%d+)%]$") + end + if start or stop then + self.source = Source(filename, tonumber(start), tonumber(stop)) + else + self.source = Source(self.source, 1, #tostring(self) + 1) + end + end end, __base = _base_0, __name = "Code" |
