Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
perf(NodeAttrs): Remove one unnecessary call to snakecase
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
vicb authored and mhevery committed Jan 7, 2014
1 parent 86b4de5 commit ad2a7d5
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/core_dom/directive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand All @@ -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<String, List<AttributeChanged>>();
}
Expand Down

0 comments on commit ad2a7d5

Please sign in to comment.