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

@@ -72,6 +72,10 @@ export class YArrayEvent extends YEvent {
* A shared Array implementation.
*/
export class YArray extends Type {
constructor () {
super()
this.length = 0
}
/**
* Creates YArray Event and calls observers.
*
@@ -167,21 +171,6 @@ export class YArray extends Type {
}
}
/**
* Computes the length of this YArray.
*/
get length () {
let length = 0
let n = this._start
while (n !== null) {
if (!n._deleted && n._countable) {
length += n._length
}
n = n._right
}
return length
}
[Symbol.iterator] () {
return {
next: function () {