@@ -85,41 +85,46 @@ class Cache[Config, Res]:
85
85
*
86
86
* The algorithmic skeleton is as follows:
87
87
*
88
+ * if don't cache result then
89
+ * return eval(expr)
88
90
* if this.current.contains(config, expr) then
89
91
* return cached value
90
92
* else
91
93
* val assumed = this.last(config, expr) or bottom value if absent
92
94
* this.current(config, expr) = assumed
93
- * val actual = eval(exp )
95
+ * val actual = eval(expr )
94
96
*
95
97
* if assumed != actual then
96
98
* this.changed = true
97
99
* this.current(config, expr) = actual
98
100
*
99
101
*/
100
102
def cachedEval (config : Config , expr : Tree , cacheResult : Boolean , default : Res )(eval : Tree => Res ): Res =
101
- this .get(config, expr) match
102
- case Some (value) => value
103
- case None =>
104
- val assumeValue : Res =
105
- this .last.get(config, expr) match
106
- case Some (value) => value
107
- case None =>
108
- this .last = this .last.updatedNested(config, expr, default)
109
- default
110
-
111
- this .current = this .current.updatedNested(config, expr, assumeValue)
112
-
113
- val actual = eval(expr)
114
- if actual != assumeValue then
115
- // println("Changed! from = " + assumeValue + ", to = " + actual)
116
- this .changed = true
117
- // TODO: respect cacheResult to reduce cache size
118
- this .current = this .current.updatedNested(config, expr, actual)
119
- // this.current = this.current.removed(config, expr)
120
- end if
121
-
122
- actual
103
+ if ! cacheResult then
104
+ eval(expr)
105
+ else
106
+ this .get(config, expr) match
107
+ case Some (value) => value
108
+ case None =>
109
+ val assumeValue : Res =
110
+ this .last.get(config, expr) match
111
+ case Some (value) => value
112
+ case None =>
113
+ this .last = this .last.updatedNested(config, expr, default)
114
+ default
115
+
116
+ this .current = this .current.updatedNested(config, expr, assumeValue)
117
+
118
+ val actual = eval(expr)
119
+ if actual != assumeValue then
120
+ // println("Changed! from = " + assumeValue + ", to = " + actual)
121
+ this .changed = true
122
+ this .current = this .current.updatedNested(config, expr, actual)
123
+ // this.current = this.current.removed(config, expr)
124
+ end if
125
+
126
+ actual
127
+ end if
123
128
end cachedEval
124
129
125
130
def hasChanged = changed
0 commit comments