Implemented more efficient garbage collectior

from worst case of O(n) -> O(1) - where n is the number of insertions in
a list

So this is a huge improvement, I guess :)
This commit is contained in:
Kevin Jahns
2016-01-23 20:09:30 +01:00
parent 38bf398709
commit 39dc2317b7
3 changed files with 63 additions and 8 deletions

View File

@@ -126,6 +126,19 @@ module.exports = function (Y/* :any */) {
execute: function *(op) {
var i // loop counter
var distanceToOrigin = i = yield* Struct.Insert.getDistanceToOrigin.call(this, op) // most cases: 0 (starts from 0)
if (op.origin != null) {
// we save in origin that op originates in it
// we need that later when we eventually garbage collect origin (see transaction)
var origin = yield* this.getOperation(op.origin)
if (origin.originOf == null) {
origin.originOf = []
}
origin.originOf.push(op.id)
yield* this.setOperation(origin)
}
// now we begin to insert op in the list of insertions..
var o
var parent
var start