Improve memory usage by omitting the ItemRef step and directly applying the Item

This commit is contained in:
Kevin Jahns
2020-06-09 00:53:05 +02:00
parent 0a0098fdfb
commit 5293ab4df1
14 changed files with 302 additions and 348 deletions

View File

@@ -1,12 +1,10 @@
import {
AbstractStructRef,
AbstractStruct,
addStruct,
StructStore, Transaction, ID // eslint-disable-line
} from '../internals.js'
import * as decoding from 'lib0/decoding.js'
import * as encoding from 'lib0/encoding.js'
export const structGCRefNumber = 0
@@ -37,8 +35,13 @@ export class GC extends AbstractStruct {
/**
* @param {Transaction} transaction
* @param {number} offset
*/
integrate (transaction) {
integrate (transaction, offset) {
if (offset > 0) {
this.id.clock += offset
this.length -= offset
}
addStruct(transaction.doc.store, this)
}
@@ -50,39 +53,13 @@ export class GC extends AbstractStruct {
encoding.writeUint8(encoder, structGCRefNumber)
encoding.writeVarUint(encoder, this.length - offset)
}
}
/**
* @private
*/
export class GCRef extends AbstractStructRef {
/**
* @param {decoding.Decoder} decoder
* @param {ID} id
* @param {number} info
*/
constructor (decoder, id, info) {
super(id)
/**
* @type {number}
*/
this.length = decoding.readVarUint(decoder)
}
/**
* @param {Transaction} transaction
* @param {StructStore} store
* @param {number} offset
* @return {GC}
* @return {null | ID}
*/
toStruct (transaction, store, offset) {
if (offset > 0) {
this.id.clock += offset
this.length -= offset
}
return new GC(
this.id,
this.length
)
getMissing (transaction, store) {
return null
}
}