@@ -3,6 +3,7 @@ package haxe.ui.styles;
3
3
import haxe .crypto .Sha1 ;
4
4
import haxe .ui .core .Component ;
5
5
import haxe .ui .styles .elements .AnimationKeyFrames ;
6
+ import haxe .ui .styles .elements .Directive ;
6
7
import haxe .ui .styles .elements .ImportElement ;
7
8
import haxe .ui .styles .elements .MediaQuery ;
8
9
import haxe .ui .styles .elements .RuleElement ;
@@ -142,18 +143,45 @@ class StyleSheet {
142
143
}
143
144
}
144
145
146
+ private var _componentStyleCache = new Map <String , Array <Map <String , Directive >>>();
147
+
145
148
public function buildStyleFor (c : Component , style : Style = null ): Style {
146
149
if (style == null ) {
147
150
style = {};
148
151
}
149
- for (r in rules ) {
150
- if (! r .match (c )) {
151
- continue ;
152
+
153
+ var styleCacheKey = @:privateAccess c .styleCacheKey ;
154
+
155
+ var cachedDirectives = _componentStyleCache .get (styleCacheKey );
156
+ if (cachedDirectives != null ) {
157
+ for (directives in cachedDirectives ) {
158
+ style .mergeDirectives (directives );
159
+ }
160
+ /*
161
+ var n = 0;
162
+ for (_ in _componentStyleCache.keys()) {
163
+ n++;
164
+ }
165
+ trace(n);
166
+ */
167
+ } else {
168
+ // trace(styleCacheKey);
169
+ cachedDirectives = [];
170
+ for (r in rules ) {
171
+ if (! r .match (c )) {
172
+ continue ;
173
+ }
174
+
175
+ cachedDirectives .push (r .directives );
152
176
}
153
177
154
- style .mergeDirectives (r .directives );
178
+ for (directives in cachedDirectives ) {
179
+ style .mergeDirectives (directives );
180
+ }
181
+ _componentStyleCache .set (styleCacheKey , cachedDirectives );
155
182
}
156
183
184
+
157
185
return style ;
158
186
}
159
187
}
0 commit comments