From 2576d4efcada261aa973ccbc57f5dd71bd4fbfcf Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Tue, 21 Feb 2023 14:35:28 +0100 Subject: [PATCH] increasing sort of ds encoding --- src/types/YXmlFragment.js | 3 ++- src/utils/DeleteSet.js | 4 ++-- src/utils/Doc.js | 2 +- src/utils/encoding.js | 7 ++++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/types/YXmlFragment.js b/src/types/YXmlFragment.js index 66c44f9a..b229a4ac 100644 --- a/src/types/YXmlFragment.js +++ b/src/types/YXmlFragment.js @@ -21,6 +21,7 @@ import { } from '../internals.js' import * as error from 'lib0/error' +import * as array from 'lib0/array' /** * Define the elements to which a set of CSS queries apply. @@ -237,7 +238,7 @@ export class YXmlFragment extends AbstractType { querySelectorAll (query) { query = query.toUpperCase() // @ts-ignore - return Array.from(new YXmlTreeWalker(this, element => element.nodeName && element.nodeName.toUpperCase() === query)) + return array.from(new YXmlTreeWalker(this, element => element.nodeName && element.nodeName.toUpperCase() === query)) } /** diff --git a/src/utils/DeleteSet.js b/src/utils/DeleteSet.js index 32fd089b..94842274 100644 --- a/src/utils/DeleteSet.js +++ b/src/utils/DeleteSet.js @@ -221,8 +221,8 @@ export const writeDeleteSet = (encoder, ds) => { encoding.writeVarUint(encoder.restEncoder, ds.clients.size) // Ensure that the delete set is written in a deterministic order - Array.from(ds.clients.entries()) - .sort((clientA, clientB) => clientA[0] - clientB[0]) + array.from(ds.clients.entries()) + .sort((a, b) => b[0] - a[0]) .forEach(([client, dsitems]) => { encoder.resetDsCurVal() encoding.writeVarUint(encoder.restEncoder, client) diff --git a/src/utils/Doc.js b/src/utils/Doc.js index 4eabd7c6..9588d362 100644 --- a/src/utils/Doc.js +++ b/src/utils/Doc.js @@ -147,7 +147,7 @@ export class Doc extends Observable { } getSubdocGuids () { - return new Set(Array.from(this.subdocs).map(doc => doc.guid)) + return new Set(array.from(this.subdocs).map(doc => doc.guid)) } /** diff --git a/src/utils/encoding.js b/src/utils/encoding.js index 29af8bc6..56e5dac1 100644 --- a/src/utils/encoding.js +++ b/src/utils/encoding.js @@ -45,6 +45,7 @@ import * as decoding from 'lib0/decoding' import * as binary from 'lib0/binary' import * as map from 'lib0/map' import * as math from 'lib0/math' +import * as array from 'lib0/array' /** * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder @@ -96,7 +97,7 @@ export const writeClientsStructs = (encoder, store, _sm) => { encoding.writeVarUint(encoder.restEncoder, sm.size) // Write items with higher client ids first // This heavily improves the conflict algorithm. - Array.from(sm.entries()).sort((a, b) => b[0] - a[0]).forEach(([client, clock]) => { + array.from(sm.entries()).sort((a, b) => b[0] - a[0]).forEach(([client, clock]) => { // @ts-ignore writeStructs(encoder, store.clients.get(client), client, clock) }) @@ -231,7 +232,7 @@ const integrateStructs = (transaction, store, clientsStructRefs) => { */ const stack = [] // sort them so that we take the higher id first, in case of conflicts the lower id will probably not conflict with the id from the higher user. - let clientsStructRefsIds = Array.from(clientsStructRefs.keys()).sort((a, b) => a - b) + let clientsStructRefsIds = array.from(clientsStructRefs.keys()).sort((a, b) => a - b) if (clientsStructRefsIds.length === 0) { return null } @@ -601,7 +602,7 @@ export const decodeStateVector = decodedState => readStateVector(new DSDecoderV1 */ export const writeStateVector = (encoder, sv) => { encoding.writeVarUint(encoder.restEncoder, sv.size) - Array.from(sv.entries()).sort((a, b) => b[0] - a[0]).forEach(([client, clock]) => { + array.from(sv.entries()).sort((a, b) => b[0] - a[0]).forEach(([client, clock]) => { encoding.writeVarUint(encoder.restEncoder, client) // @todo use a special client decoder that is based on mapping encoding.writeVarUint(encoder.restEncoder, clock) })