Browse Source

Code cleanups

Dmitry Panov 6 years ago
parent
commit
7122a20638
5 changed files with 6 additions and 19 deletions
  1. 1 5
      array.go
  2. 1 5
      array_sparse.go
  3. 1 1
      compiler.go
  4. 2 7
      compiler_expr.go
  5. 1 1
      token/token.go

+ 1 - 5
array.go

@@ -22,10 +22,6 @@ func (a *arrayObject) init() {
 	a._put("length", &a.lengthProp)
 	a._put("length", &a.lengthProp)
 }
 }
 
 
-func (a *arrayObject) getLength() Value {
-	return intToValue(a.length)
-}
-
 func (a *arrayObject) _setLengthInt(l int64, throw bool) bool {
 func (a *arrayObject) _setLengthInt(l int64, throw bool) bool {
 	if l >= 0 && l <= math.MaxUint32 {
 	if l >= 0 && l <= math.MaxUint32 {
 		ret := true
 		ret := true
@@ -57,7 +53,7 @@ func (a *arrayObject) _setLengthInt(l int64, throw bool) bool {
 				a.values = ar
 				a.values = ar
 			} else {
 			} else {
 				ar := a.values[l:len(a.values)]
 				ar := a.values[l:len(a.values)]
-				for i, _ := range ar {
+				for i := range ar {
 					ar[i] = nil
 					ar[i] = nil
 				}
 				}
 				a.values = a.values[:l]
 				a.values = a.values[:l]

+ 1 - 5
array_sparse.go

@@ -27,10 +27,6 @@ func (a *sparseArrayObject) init() {
 	a._put("length", &a.lengthProp)
 	a._put("length", &a.lengthProp)
 }
 }
 
 
-func (a *sparseArrayObject) getLength() Value {
-	return intToValue(a.length)
-}
-
 func (a *sparseArrayObject) findIdx(idx int64) int {
 func (a *sparseArrayObject) findIdx(idx int64) int {
 	return sort.Search(len(a.items), func(i int) bool {
 	return sort.Search(len(a.items), func(i int) bool {
 		return a.items[i].idx >= idx
 		return a.items[i].idx >= idx
@@ -64,7 +60,7 @@ func (a *sparseArrayObject) _setLengthInt(l int64, throw bool) bool {
 		idx := a.findIdx(l)
 		idx := a.findIdx(l)
 
 
 		aa := a.items[idx:]
 		aa := a.items[idx:]
-		for i, _ := range aa {
+		for i := range aa {
 			aa[i].value = nil
 			aa[i].value = nil
 		}
 		}
 		a.items = a.items[:idx]
 		a.items = a.items[:idx]

+ 1 - 1
compiler.go

@@ -278,7 +278,7 @@ func (c *compiler) compile(in *ast.Program) {
 	}
 	}
 
 
 	c.p.code = append(c.p.code, code...)
 	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)
 		c.p.srcMap[i].pc += len(c.scope.names)
 	}
 	}
 
 

+ 2 - 7
compiler_expr.go

@@ -770,11 +770,6 @@ func (e *compiledFunctionLiteral) emitGetter(putOnStack bool) {
 			needCallee = true
 			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
 	maxPreambleLen := 2
 	e.c.p.code = make([]instruction, maxPreambleLen)
 	e.c.p.code = make([]instruction, maxPreambleLen)
 	if needCallee {
 	if needCallee {
@@ -801,7 +796,7 @@ func (e *compiledFunctionLiteral) emitGetter(putOnStack bool) {
 			e.c.p.code = e.c.p.code[maxPreambleLen-1:]
 			e.c.p.code = e.c.p.code[maxPreambleLen-1:]
 		}
 		}
 		e.c.convertFunctionToStashless(e.c.p.code, paramsCount)
 		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
 			e.c.p.srcMap[i].pc -= maxPreambleLen - l
 		}
 		}
 	} else {
 	} else {
@@ -842,7 +837,7 @@ func (e *compiledFunctionLiteral) emitGetter(putOnStack bool) {
 
 
 		copy(code[l:], e.c.p.code[maxPreambleLen:])
 		copy(code[l:], e.c.p.code[maxPreambleLen:])
 		e.c.p.code = code
 		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
 			e.c.p.srcMap[i].pc += l - maxPreambleLen
 		}
 		}
 	}
 	}

+ 1 - 1
token/token.go

@@ -15,7 +15,7 @@ type Token int
 // name (e.g. for the token IDENTIFIER, the string is "IDENTIFIER").
 // name (e.g. for the token IDENTIFIER, the string is "IDENTIFIER").
 //
 //
 func (tkn Token) String() string {
 func (tkn Token) String() string {
-	if 0 == tkn {
+	if tkn == 0 {
 		return "UNKNOWN"
 		return "UNKNOWN"
 	}
 	}
 	if tkn < Token(len(token2string)) {
 	if tkn < Token(len(token2string)) {