diff --git a/haxe/ui/core/Component.hx b/haxe/ui/core/Component.hx index 21b51c0a0..c24006718 100644 --- a/haxe/ui/core/Component.hx +++ b/haxe/ui/core/Component.hx @@ -1243,6 +1243,30 @@ class Component extends ComponentImpl // Style related //*********************************************************************************************************** + private var _styleCacheKey:String = null; + private var styleCacheKey(get, never):String; + private function get_styleCacheKey():String { + if (_styleCacheKey == null) { + var sb = new StringBuf(); + var ref = this; + do { + sb.add(ref.className); + sb.add("_id:"); + sb.add(ref.id); + sb.add("_classes:"); + for (c in ref.classes) { + sb.add(c); + sb.add("|"); + } + ref = ref.parentComponent; + } while (ref != null); + + //_styleCacheKey = sb.toString(); + return sb.toString(); + } + return _styleCacheKey; + } + @:noCompletion private var _customStyle:Style = null; /** diff --git a/haxe/ui/styles/StyleSheet.hx b/haxe/ui/styles/StyleSheet.hx index aa2ec2856..104130d49 100644 --- a/haxe/ui/styles/StyleSheet.hx +++ b/haxe/ui/styles/StyleSheet.hx @@ -3,6 +3,7 @@ package haxe.ui.styles; import haxe.crypto.Sha1; import haxe.ui.core.Component; import haxe.ui.styles.elements.AnimationKeyFrames; +import haxe.ui.styles.elements.Directive; import haxe.ui.styles.elements.ImportElement; import haxe.ui.styles.elements.MediaQuery; import haxe.ui.styles.elements.RuleElement; @@ -142,18 +143,45 @@ class StyleSheet { } } + private var _componentStyleCache = new Map>>(); + public function buildStyleFor(c:Component, style:Style = null):Style { if (style == null) { style = {}; } - for (r in rules) { - if (!r.match(c)) { - continue; + + var styleCacheKey = @:privateAccess c.styleCacheKey; + + var cachedDirectives = _componentStyleCache.get(styleCacheKey); + if (cachedDirectives != null) { + for (directives in cachedDirectives) { + style.mergeDirectives(directives); + } + /* + var n = 0; + for (_ in _componentStyleCache.keys()) { + n++; + } + trace(n); + */ + } else { + //trace(styleCacheKey); + cachedDirectives = []; + for (r in rules) { + if (!r.match(c)) { + continue; + } + + cachedDirectives.push(r.directives); } - style.mergeDirectives(r.directives); + for (directives in cachedDirectives) { + style.mergeDirectives(directives); + } + _componentStyleCache.set(styleCacheKey, cachedDirectives); } + return style; } } \ No newline at end of file