perf(RecordRange): optimize disable()

There could be no lastEnabledChildRecord when there is no
firstEnabledChildRecord
- saves time by skipping findLastEnabledRecord() when the result is know
to be null,
- saves a test as isPresent(lastEnabledChildRecord) ==
isPresent(firstEnabledChildRecord)
This commit is contained in:
Victor Berchet 2014-12-04 10:51:28 +01:00
parent 27e03591dd
commit 5c531f718e
2 changed files with 12 additions and 15 deletions

View File

@ -149,14 +149,13 @@ export class RecordRange {
remove() {
var firstEnabledChildRecord = this.findFirstEnabledRecord();
var lastEnabledChildRecord = this.findLastEnabledRecord();
var next = this.tailRecord.next;
var prev = this.headRecord.prev;
_link(prev, next);
if (isPresent(firstEnabledChildRecord)) {
var lastEnabledChildRecord = this.findLastEnabledRecord();
var nextEnabled = lastEnabledChildRecord.nextEnabled;
var prevEnabled = firstEnabledChildRecord.prevEnabled;
if (isPresent(nextEnabled)) nextEnabled.prevEnabled = prevEnabled;
@ -191,16 +190,14 @@ export class RecordRange {
disable() {
var firstEnabledChildRecord = this.findFirstEnabledRecord();
if (isPresent(firstEnabledChildRecord)) {
// There could be a last enabled record only if first enabled exists
var lastEnabledChildRecord = this.findLastEnabledRecord();
var nextEnabled = isPresent(lastEnabledChildRecord) ?
lastEnabledChildRecord.nextEnabled : null;
var prevEnabled = isPresent(firstEnabledChildRecord) ?
firstEnabledChildRecord.prevEnabled : null;
var nextEnabled = lastEnabledChildRecord.nextEnabled;
var prevEnabled = firstEnabledChildRecord.prevEnabled;
if (isPresent(nextEnabled)) nextEnabled.prevEnabled = prevEnabled;
if (isPresent(prevEnabled)) prevEnabled.nextEnabled = nextEnabled;
}
this.disabled = true;
}