From ad2a7d54e86d681a976737c63a30b91a3fca1de7 Mon Sep 17 00:00:00 2001 From: Victor Date: Thu, 19 Dec 2013 17:06:31 +0100 Subject: [PATCH] perf(NodeAttrs): Remove one unnecessary call to snakecase The `_observers` map is now indexed by camelCase names, saving 1 call to `snakeCase`. `this[attributeName]` was also resulting in calling `snakecase` on an already snake-name (which is not an error). --- lib/core_dom/directive.dart | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/core_dom/directive.dart b/lib/core_dom/directive.dart index 6b1374d11..23c1b2328 100644 --- a/lib/core_dom/directive.dart +++ b/lib/core_dom/directive.dart @@ -24,17 +24,18 @@ class NodeAttrs { NodeAttrs(this.element); - operator [](String name) => element.attributes[snakecase(name, '-')]; + operator [](String attributeName) => + element.attributes[snakecase(attributeName, '-')]; - operator []=(String name, String value) { - name = snakecase(name, '-'); + operator []=(String attributeName, String value) { + var snakeName = snakecase(attributeName, '-'); if (value == null) { - element.attributes.remove(name); + element.attributes.remove(snakeName); } else { - element.attributes[name] = value; + element.attributes[snakeName] = value; } - if (_observers != null && _observers.containsKey(name)) { - _observers[name].forEach((fn) => fn(value)); + if (_observers != null && _observers.containsKey(attributeName)) { + _observers[attributeName].forEach((fn) => fn(value)); } } @@ -44,7 +45,6 @@ class NodeAttrs { * synchronise with the current value. */ observe(String attributeName, AttributeChanged notifyFn) { - attributeName = snakecase(attributeName, '-'); if (_observers == null) { _observers = new Map>(); }