perf(ProtoRecordRange): re-use a ProtoRecordCreator
This commit is contained in:
parent
f8c070c5e4
commit
0f3134acd4
|
@ -36,11 +36,9 @@ import {
|
||||||
} from './parser/ast';
|
} from './parser/ast';
|
||||||
|
|
||||||
export class ProtoRecordRange {
|
export class ProtoRecordRange {
|
||||||
headRecord:ProtoRecord;
|
recordCreator: ProtoRecordCreator;
|
||||||
tailRecord:ProtoRecord;
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.headRecord = null;
|
this.recordCreator = null;
|
||||||
this.tailRecord = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,30 +53,20 @@ export class ProtoRecordRange {
|
||||||
memento,
|
memento,
|
||||||
content:boolean = false)
|
content:boolean = false)
|
||||||
{
|
{
|
||||||
var creator = new ProtoRecordCreator(this);
|
if (this.recordCreator === null) {
|
||||||
|
this.recordCreator = new ProtoRecordCreator(this);
|
||||||
|
}
|
||||||
if (content) {
|
if (content) {
|
||||||
ast = new Collection(ast);
|
ast = new Collection(ast);
|
||||||
}
|
}
|
||||||
creator.createRecordsFromAST(ast, memento);
|
this.recordCreator.createRecordsFromAST(ast, memento);
|
||||||
this._addRecords(creator.headRecord, creator.tailRecord);
|
|
||||||
}
|
|
||||||
|
|
||||||
// try to encapsulate this behavior in some class (e.g., LinkedList)
|
|
||||||
// so we can say: group.appendList(creator.list);
|
|
||||||
_addRecords(head:ProtoRecord, tail:ProtoRecord) {
|
|
||||||
if (isBlank(this.headRecord)) {
|
|
||||||
this.headRecord = head;
|
|
||||||
} else {
|
|
||||||
this.tailRecord.next = head;
|
|
||||||
}
|
|
||||||
this.tailRecord = tail;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(rado): the type annotation should be dispatcher:WatchGroupDispatcher.
|
// TODO(rado): the type annotation should be dispatcher:WatchGroupDispatcher.
|
||||||
// but @Implements is not ready yet.
|
// but @Implements is not ready yet.
|
||||||
instantiate(dispatcher, formatters:Map):RecordRange {
|
instantiate(dispatcher, formatters:Map):RecordRange {
|
||||||
var recordRange:RecordRange = new RecordRange(this, dispatcher);
|
var recordRange:RecordRange = new RecordRange(this, dispatcher);
|
||||||
if (this.headRecord !== null) {
|
if (this.recordCreator !== null) {
|
||||||
this._createRecords(recordRange, formatters);
|
this._createRecords(recordRange, formatters);
|
||||||
this._setDestination();
|
this._setDestination();
|
||||||
}
|
}
|
||||||
|
@ -86,7 +74,7 @@ export class ProtoRecordRange {
|
||||||
}
|
}
|
||||||
|
|
||||||
_createRecords(recordRange:RecordRange, formatters:Map) {
|
_createRecords(recordRange:RecordRange, formatters:Map) {
|
||||||
for (var proto = this.headRecord; proto != null; proto = proto.next) {
|
for (var proto = this.recordCreator.headRecord; proto != null; proto = proto.next) {
|
||||||
var record = new Record(recordRange, proto, formatters);
|
var record = new Record(recordRange, proto, formatters);
|
||||||
proto.recordInConstruction = record;
|
proto.recordInConstruction = record;
|
||||||
recordRange.addRecord(record);
|
recordRange.addRecord(record);
|
||||||
|
@ -94,7 +82,7 @@ export class ProtoRecordRange {
|
||||||
}
|
}
|
||||||
|
|
||||||
_setDestination() {
|
_setDestination() {
|
||||||
for (var proto = this.headRecord; proto != null; proto = proto.next) {
|
for (var proto = this.recordCreator.headRecord; proto != null; proto = proto.next) {
|
||||||
if (proto.dest instanceof Destination) {
|
if (proto.dest instanceof Destination) {
|
||||||
proto.recordInConstruction.dest = proto.dest.record.recordInConstruction;
|
proto.recordInConstruction.dest = proto.dest.record.recordInConstruction;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue