Browse Source

Eliminate multiplication

James 5 years ago
parent
commit
a7ff94e75f
1 changed files with 3 additions and 3 deletions
  1. 3 3
      src/main/java/com/jfinal/template/expr/ast/RangeArray.java

+ 3 - 3
src/main/java/com/jfinal/template/expr/ast/RangeArray.java

@@ -68,12 +68,12 @@ public class RangeArray extends Expr {
 		
 		final int start;
 		final int size;
-		final int increment;
+		final boolean increase;
 		final Location location;
 		
 		public RangeList(int start, int end, Location location) {
 			this.start = start;
-			this.increment = start <= end ? 1 : -1;
+			this.increase = (start <= end);
 			this.size = Math.abs(end - start) + 1;
 			this.location = location;
 		}
@@ -82,7 +82,7 @@ public class RangeArray extends Expr {
 			if (index < 0 || index >= size) {
 				throw new TemplateException("Index out of bounds. Index: " + index + ", Size: " + size, location);
 			}
-			return start + index * increment;
+			return increase ? start + index : start - index;
 		}
 		
 		public int size() {