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

[WIP] Feature/micromap #1230

Closed
wants to merge 11 commits into from
48 changes: 27 additions & 21 deletions benchmark/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ packages:
analyzer:
description: analyzer
source: hosted
version: "0.15.7"
version: "0.18.0"
angular:
description:
path: ".."
relative: true
source: path
version: "0.11.0"
version: "0.13.0"
args:
description: args
source: hosted
version: "0.10.0+2"
barback:
description: barback
source: hosted
version: "0.13.0"
version: "0.14.0+3"
benchmark_harness:
description: benchmark_harness
source: hosted
Expand All @@ -30,66 +30,72 @@ packages:
code_transformers:
description: code_transformers
source: hosted
version: "0.1.4+2"
version: "0.1.6"
collection:
description: collection
source: hosted
version: "0.9.2"
version: "0.9.4"
di:
description:
path: "../../di.dart"
relative: true
source: path
version: "2.0.0-alpha.9"
description: di
source: hosted
version: "2.0.1"
html5lib:
description: html5lib
source: hosted
version: "0.10.0"
intl:
description: intl
source: hosted
version: "0.9.10"
version: "0.11.4"
logging:
description: logging
source: hosted
version: "0.9.1+1"
version: "0.9.2"
matcher:
description: matcher
source: hosted
version: "0.10.0"
version: "0.11.1"
mock:
description: mock
source: hosted
version: "0.10.0+1"
version: "0.11.0+2"
path:
description: path
source: hosted
version: "1.2.1"
version: "1.3.0"
perf_api:
description: perf_api
source: hosted
version: "0.0.8"
version: "0.0.9"
route_hierarchical:
description: route_hierarchical
source: hosted
version: "0.4.21"
source_maps:
description: source_maps
source: hosted
version: "0.9.0"
version: "0.9.4"
source_span:
description: source_span
source: hosted
version: "1.0.0"
stack_trace:
description: stack_trace
source: hosted
version: "0.9.3+1"
version: "0.9.3+2"
typed_mock:
description: typed_mock
source: hosted
version: "0.0.4"
unittest:
description: unittest
source: hosted
version: "0.10.1+2"
version: "0.11.0+4"
utf:
description: utf
source: hosted
version: "0.9.0"
version: "0.9.0+1"
web_components:
description: web_components
source: hosted
version: "0.3.3"
version: "0.3.5+1"
35 changes: 4 additions & 31 deletions lib/change_detection/prototype_map.dart
Original file line number Diff line number Diff line change
@@ -1,39 +1,12 @@
part of angular.watch_group;

class PrototypeMap<K, V> implements Map<K,V> {
class PrototypeMap<K, V> extends MicroMap<K,V> {
final Map<K, V> prototype;
final Map<K, V> self = new HashMap();

PrototypeMap(this.prototype);

void operator []=(name, value) {
self[name] = value;
}
V operator [](name) => self.containsKey(name) ? self[name] : prototype[name];
V operator [](name) => containsKey(name) ? super[name] : prototype[name];

bool get isEmpty => self.isEmpty && prototype.isEmpty;
bool get isNotEmpty => self.isNotEmpty || prototype.isNotEmpty;
// todo(vbe) include prototype keys ?
Iterable<K> get keys => self.keys;
// todo(vbe) include prototype values ?
Iterable<V> get values => self.values;
int get length => self.length;

void forEach(fn) {
// todo(vbe) include prototype ?
self.forEach(fn);
}
V remove(key) => self.remove(key);
clear() => self.clear;
// todo(vbe) include prototype ?
bool containsKey(key) => self.containsKey(key);
// todo(vbe) include prototype ?
bool containsValue(key) => self.containsValue(key);
void addAll(map) {
self.addAll(map);
}
// todo(vbe) include prototype ?
V putIfAbsent(key, fn) => self.putIfAbsent(key, fn);

toString() => self.toString();
bool get isEmpty => _count == 0 && prototype.isEmpty;
bool get isNotEmpty => _count != 0 || prototype.isNotEmpty;
}
7 changes: 4 additions & 3 deletions lib/change_detection/watch_group.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
library angular.watch_group;

import 'package:angular/change_detection/change_detection.dart';
import 'package:angular/collection/micro_map.dart';
import 'dart:collection';

part 'linked_list.dart';
Expand Down Expand Up @@ -54,7 +55,7 @@ class WatchGroup implements _EvalWatchList, _WatchGroupList {
final ChangeDetectorGroup<_Handler> _changeDetector;
/** A cache for sharing sub expression watching. Watching `a` and `a.b` will
* watch `a` only once. */
final Map<String, WatchRecord<_Handler>> _cache;
final MicroMap<String, WatchRecord<_Handler>> _cache;
final RootWatchGroup _rootGroup;

/// STATS: Number of field watchers which are in use.
Expand Down Expand Up @@ -120,7 +121,7 @@ class WatchGroup implements _EvalWatchList, _WatchGroupList {
: id = '',
_rootGroup = null,
_parentWatchGroup = null,
_cache = new HashMap<String, WatchRecord<_Handler>>()
_cache = new MicroMap<String, WatchRecord<_Handler>>()
{
_marker.watchGrp = this;
_evalWatchTail = _evalWatchHead = _marker;
Expand Down Expand Up @@ -301,7 +302,7 @@ class WatchGroup implements _EvalWatchList, _WatchGroupList {
this,
_changeDetector.newGroup(),
context == null ? this.context : context,
new HashMap<String, WatchRecord<_Handler>>(),
new MicroMap<String, WatchRecord<_Handler>>(),
_rootGroup == null ? this : _rootGroup);
_WatchGroupList._add(this, childGroup);
var marker = childGroup._marker;
Expand Down
Loading