Browse code

Add nexti/previ to for loop variables

Nat! authored on 18-08-2016 12:15:13
Showing 6 changed files
... ...
@@ -1963,7 +1963,7 @@
1963 1963
 			baseConfigurationReference = 413C51611CC284CA00F62468 /* Debug.xcconfig */;
1964 1964
 			buildSettings = {
1965 1965
 				CLANG_WARN_INT_CONVERSION = YES;
1966
-				CURRENT_PROJECT_VERSION = 1855;
1966
+				CURRENT_PROJECT_VERSION = 1856;
1967 1967
 				DYLIB_COMPATIBILITY_VERSION = 1848.0;
1968 1968
 				DYLIB_CURRENT_VERSION = "$(CURRENT_PROJECT_VERSION)";
1969 1969
 				GCC_OPTIMIZATION_LEVEL = 0;
... ...
@@ -1995,7 +1995,7 @@
1995 1995
 			baseConfigurationReference = 413C516B1CC284CA00F62468 /* Release.xcconfig */;
1996 1996
 			buildSettings = {
1997 1997
 				CLANG_WARN_INT_CONVERSION = YES;
1998
-				CURRENT_PROJECT_VERSION = 1855;
1998
+				CURRENT_PROJECT_VERSION = 1856;
1999 1999
 				DYLIB_COMPATIBILITY_VERSION = 1848.0;
2000 2000
 				DYLIB_CURRENT_VERSION = "$(CURRENT_PROJECT_VERSION)";
2001 2001
 				GCC_PREPROCESSOR_DEFINITIONS = (
... ...
@@ -2064,7 +2064,7 @@
2064 2064
 			baseConfigurationReference = 413C516B1CC284CA00F62468 /* Release.xcconfig */;
2065 2065
 			buildSettings = {
2066 2066
 				CLANG_WARN_INT_CONVERSION = YES;
2067
-				CURRENT_PROJECT_VERSION = 1855;
2067
+				CURRENT_PROJECT_VERSION = 1856;
2068 2068
 				DYLIB_COMPATIBILITY_VERSION = 1848.0;
2069 2069
 				DYLIB_CURRENT_VERSION = "$(CURRENT_PROJECT_VERSION)";
2070 2070
 				GCC_PREPROCESSOR_DEFINITIONS = (
... ...
@@ -1,3 +1,7 @@
1
+## 1856
2
+
3
+* add nexti/previ to for loop dictionary.
4
+
1 5
 ## 1855
2 6
 
3 7
 * Bool fix from Hannes Tribus `<hons82@...com>`
... ...
@@ -21,7 +21,11 @@ Name                | Description
21 21
 `footer`            | see below
22 22
 `division`          | see below
23 23
 `modulo`            | see below
24
+                    |
24 25
 `i`                 | the loop count
26
+`previ`             | the loop count - 1
27
+`nexti`             | the loop count + 1
28
+                    |
25 29
 `isFirst`           | will be set YES, if it's the first loop iteration
26 30
 `isEven`            | will be set YES, if the loop count is even  (0,2,4 ...)
27 31
 `isLast`            | will be set YES, if it's the last loop iteration
... ...
@@ -1498,6 +1498,7 @@ static BOOL  isTrue( id value)
1498 1498
    NSUInteger            i;
1499 1499
    NSInteger             division;
1500 1500
    NSNumber              *yes, *no;
1501
+   NSNumber              *oldi, *newi, *newi1;
1501 1502
    id                    value;
1502 1503
    
1503 1504
    TRACE_RENDER( self, s, locals, dataSource);
... ...
@@ -1572,7 +1573,7 @@ static BOOL  isTrue( id value)
1572 1573
    if( ! identifier)
1573 1574
       goto done;
1574 1575
    
1575
-   info    = [NSMutableDictionary dictionary];
1576
+   info    = [NSMutableDictionary dictionaryWithCapacity:16];
1576 1577
    infoKey = [NSString stringWithFormat:@"%@#", identifier];
1577 1578
    [locals setObject:info
1578 1579
               forKey:infoKey];
... ...
@@ -1581,6 +1582,7 @@ static BOOL  isTrue( id value)
1581 1582
    no   = [NSNumber numberWithBool:NO];
1582 1583
 
1583 1584
    i    = 0;
1585
+   newi = nil;
1584 1586
    next = [rover nextObject];
1585 1587
    while( key = next)
1586 1588
    {
... ...
@@ -1594,11 +1596,29 @@ static BOOL  isTrue( id value)
1594 1596
       isSubdivisionEnd   = (i % division) == (NSUInteger) (division - 1);
1595 1597
       isSubdivisionStart = ! (i % division);
1596 1598
 
1597
-      [info setObject:[NSNumber numberWithInteger:i]
1599
+      // try to reuse previous NSNumbers
1600
+      if( ! newi)
1601
+      {
1602
+         oldi  = [NSNumber numberWithInteger:i - 1];
1603
+         newi  = [NSNumber numberWithInteger:i];
1604
+      }
1605
+      else
1606
+      {
1607
+         oldi  = newi;
1608
+         newi  = newi1;
1609
+      }
1610
+      newi1 = [NSNumber numberWithInteger:i + 1];
1611
+      
1612
+      [info setObject:newi
1598 1613
                forKey:@"i"];
1614
+      [info setObject:newi1
1615
+               forKey:@"nexti"];
1616
+      [info setObject:oldi
1617
+               forKey:@"previ"];
1618
+
1599 1619
       [info setObject:[NSNumber numberWithInteger:i % division]
1600 1620
                forKey:@"modulo"];
1601
-      [info setObject:[NSNumber numberWithInteger:i / division]
1621
+      [info setObject:division == 1 ? newi : [NSNumber numberWithInteger:i / division]
1602 1622
                forKey:@"division"];
1603 1623
       
1604 1624
       [info setObject:isFirst ? opener : (isSubdivisionStart ? subdivisionOpener : @"")
1605 1625
new file mode 100644
... ...
@@ -0,0 +1,10 @@
1
+{% for number in @( 1, 2, 3) %}
2
+number={{ number }}
3
+i={{ number#.i }}
4
+previ={{ number#.previ }}
5
+nexti={{ number#.nexti }}
6
+isFirst={{ number#.isFirst }}
7
+isLast={{ number#.isLast }}
8
+isEven={{ number#.isEven }}
9
+evenOdd={{ number#.evenOdd }}
10
+{% endfor %}
0 11
\ No newline at end of file
1 12
new file mode 100644
... ...
@@ -0,0 +1,24 @@
1
+number=1
2
+i=0
3
+previ=-1
4
+nexti=1
5
+isFirst=1
6
+isLast=0
7
+isEven=1
8
+evenOdd=even
9
+number=2
10
+i=1
11
+previ=0
12
+nexti=2
13
+isFirst=0
14
+isLast=0
15
+isEven=0
16
+evenOdd=odd
17
+number=3
18
+i=2
19
+previ=1
20
+nexti=3
21
+isFirst=0
22
+isLast=1
23
+isEven=1
24
+evenOdd=even