aboutsummaryrefslogtreecommitdiff
path: root/code_obj.moon
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-05-14 14:45:38 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-05-14 14:45:45 -0700
commit7410e42bc00c8438884a475ccf8a9e07b73eaec3 (patch)
treefc8bec6c4c2a885aceb75fc784bdc4d07cd5392f /code_obj.moon
parent95ee15982bb021e94a4976741a0bcdfe5f5d6992 (diff)
Minor optimizations.
Diffstat (limited to 'code_obj.moon')
-rw-r--r--code_obj.moon23
1 files changed, 11 insertions, 12 deletions
diff --git a/code_obj.moon b/code_obj.moon
index 3364cdf..caccd2b 100644
--- a/code_obj.moon
+++ b/code_obj.moon
@@ -62,8 +62,18 @@ Source = immutable {"filename","start","stop"}, {
class Code
new: (@source, ...)=>
- @indents = {}
@bits = {...}
+ indent, indents = 0, {}
+ match = string.match
+ for i,b in ipairs @bits
+ if type(b) == 'string'
+ if spaces = match(b, "\n([ ]*)[^\n]*$")
+ indent = #spaces
+ elseif indent != 0
+ indents[i] = indent
+ @current_indent = indent
+ @indents = indents
+ @__str = nil
if type(@source) == 'string'
filename,start,stop = @source\match("^(.-)%[(%d+):(%d+)%]$")
unless filename
@@ -72,17 +82,6 @@ class Code
@source = Source(filename, tonumber(start), tonumber(stop))
else
@source = Source(@source, 1, #tostring(self)+1)
- assert(@source == nil or Source\is_instance(@source))
- indent = 0
- for i,b in ipairs @bits
- assert(not Source\is_instance(b))
- if type(b) == 'string'
- if spaces = b\match("\n([ ]*)[^\n]*$")
- indent = #spaces
- elseif indent != 0
- @indents[i] = indent
- @current_indent = indent
- @__str = nil
sub: (start,stop)=>
-- TODO: implement this better