more efficient length computing

This commit is contained in:
Kevin Jahns
2018-11-28 13:20:14 +01:00
parent a2c51c36e9
commit c9ea3a412e
3 changed files with 18 additions and 17 deletions

View File

@@ -251,16 +251,22 @@ export class Item {
*/
_delete (y, createDelete = true, gcChildren) {
if (!this._deleted) {
const parent = this._parent
const len = this._length
// adjust the length of parent
if (parent.length !== undefined && this._countable) {
parent.length -= len
}
this._deleted = true
y.ds.mark(this._id, this._length, false)
let del = new Delete()
del._targetID = this._id
del._length = this._length
del._length = len
if (createDelete) {
// broadcast and persists Delete
del._integrate(y, true)
}
transactionTypeChanged(y, this._parent, this._parentSub)
transactionTypeChanged(y, parent, this._parentSub)
y._transaction.deletedStructs.add(this)
}
}
@@ -410,6 +416,10 @@ export class Item {
right._left = this
}
}
// adjust the length of parent
if (parent.length !== undefined && this._countable) {
parent.length += this._length
}
if (parent._deleted) {
this._delete(y, false, true)
}