Skip to content

Commit

Permalink
Code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
dop251 committed Jun 23, 2019
1 parent e055638 commit 7122a20
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 19 deletions.
6 changes: 1 addition & 5 deletions array.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ func (a *arrayObject) init() {
a._put("length", &a.lengthProp)
}

func (a *arrayObject) getLength() Value {
return intToValue(a.length)
}

func (a *arrayObject) _setLengthInt(l int64, throw bool) bool {
if l >= 0 && l <= math.MaxUint32 {
ret := true
Expand Down Expand Up @@ -57,7 +53,7 @@ func (a *arrayObject) _setLengthInt(l int64, throw bool) bool {
a.values = ar
} else {
ar := a.values[l:len(a.values)]
for i, _ := range ar {
for i := range ar {
ar[i] = nil
}
a.values = a.values[:l]
Expand Down
6 changes: 1 addition & 5 deletions array_sparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ func (a *sparseArrayObject) init() {
a._put("length", &a.lengthProp)
}

func (a *sparseArrayObject) getLength() Value {
return intToValue(a.length)
}

func (a *sparseArrayObject) findIdx(idx int64) int {
return sort.Search(len(a.items), func(i int) bool {
return a.items[i].idx >= idx
Expand Down Expand Up @@ -64,7 +60,7 @@ func (a *sparseArrayObject) _setLengthInt(l int64, throw bool) bool {
idx := a.findIdx(l)

aa := a.items[idx:]
for i, _ := range aa {
for i := range aa {
aa[i].value = nil
}
a.items = a.items[:idx]
Expand Down
2 changes: 1 addition & 1 deletion compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (c *compiler) compile(in *ast.Program) {
}

c.p.code = append(c.p.code, code...)
for i, _ := range c.p.srcMap {
for i := range c.p.srcMap {
c.p.srcMap[i].pc += len(c.scope.names)
}

Expand Down
9 changes: 2 additions & 7 deletions compiler_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,11 +770,6 @@ func (e *compiledFunctionLiteral) emitGetter(putOnStack bool) {
needCallee = true
}
}
lenBefore := len(e.c.scope.names)
namesBefore := make([]string, 0, lenBefore)
for key, _ := range e.c.scope.names {
namesBefore = append(namesBefore, key)
}
maxPreambleLen := 2
e.c.p.code = make([]instruction, maxPreambleLen)
if needCallee {
Expand All @@ -801,7 +796,7 @@ func (e *compiledFunctionLiteral) emitGetter(putOnStack bool) {
e.c.p.code = e.c.p.code[maxPreambleLen-1:]
}
e.c.convertFunctionToStashless(e.c.p.code, paramsCount)
for i, _ := range e.c.p.srcMap {
for i := range e.c.p.srcMap {
e.c.p.srcMap[i].pc -= maxPreambleLen - l
}
} else {
Expand Down Expand Up @@ -842,7 +837,7 @@ func (e *compiledFunctionLiteral) emitGetter(putOnStack bool) {

copy(code[l:], e.c.p.code[maxPreambleLen:])
e.c.p.code = code
for i, _ := range e.c.p.srcMap {
for i := range e.c.p.srcMap {
e.c.p.srcMap[i].pc += l - maxPreambleLen
}
}
Expand Down
2 changes: 1 addition & 1 deletion token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Token int
// name (e.g. for the token IDENTIFIER, the string is "IDENTIFIER").
//
func (tkn Token) String() string {
if 0 == tkn {
if tkn == 0 {
return "UNKNOWN"
}
if tkn < Token(len(token2string)) {
Expand Down

0 comments on commit 7122a20

Please sign in to comment.