fix: use switch instead of ifs
This commit is contained in:
parent
9a7b659919
commit
53558645c3
@ -49,34 +49,40 @@ function * lazyStructReaderGenerator (decoder) {
|
|||||||
let clock = decoding.readVarUint(decoder.restDecoder)
|
let clock = decoding.readVarUint(decoder.restDecoder)
|
||||||
for (let i = 0; i < numberOfStructs; i++) {
|
for (let i = 0; i < numberOfStructs; i++) {
|
||||||
const info = decoder.readInfo()
|
const info = decoder.readInfo()
|
||||||
// @todo use switch instead of ifs
|
switch (true) {
|
||||||
if (info === 10) {
|
case (info === 10): {
|
||||||
const len = decoding.readVarUint(decoder.restDecoder)
|
const len = decoding.readVarUint(decoder.restDecoder)
|
||||||
yield new Skip(createID(client, clock), len)
|
yield new Skip(createID(client, clock), len)
|
||||||
clock += len
|
clock += len
|
||||||
} else if ((binary.BITS5 & info) !== 0) {
|
break
|
||||||
const cantCopyParentInfo = (info & (binary.BIT7 | binary.BIT8)) === 0
|
}
|
||||||
// If parent = null and neither left nor right are defined, then we know that `parent` is child of `y`
|
case ((binary.BITS5 & info) !== 0): {
|
||||||
// and we read the next string as parentYKey.
|
const cantCopyParentInfo = (info & (binary.BIT7 | binary.BIT8)) === 0
|
||||||
// It indicates how we store/retrieve parent from `y.share`
|
// If parent = null and neither left nor right are defined, then we know that `parent` is child of `y`
|
||||||
// @type {string|null}
|
// and we read the next string as parentYKey.
|
||||||
const struct = new Item(
|
// It indicates how we store/retrieve parent from `y.share`
|
||||||
createID(client, clock),
|
// @type {string|null}
|
||||||
null, // left
|
const struct = new Item(
|
||||||
(info & binary.BIT8) === binary.BIT8 ? decoder.readLeftID() : null, // origin
|
createID(client, clock),
|
||||||
null, // right
|
null, // left
|
||||||
(info & binary.BIT7) === binary.BIT7 ? decoder.readRightID() : null, // right origin
|
(info & binary.BIT8) === binary.BIT8 ? decoder.readLeftID() : null, // origin
|
||||||
// @ts-ignore Force writing a string here.
|
null, // right
|
||||||
cantCopyParentInfo ? (decoder.readParentInfo() ? decoder.readString() : decoder.readLeftID()) : null, // parent
|
(info & binary.BIT7) === binary.BIT7 ? decoder.readRightID() : null, // right origin
|
||||||
cantCopyParentInfo && (info & binary.BIT6) === binary.BIT6 ? decoder.readString() : null, // parentSub
|
// @ts-ignore Force writing a string here.
|
||||||
readItemContent(decoder, info) // item content
|
cantCopyParentInfo ? (decoder.readParentInfo() ? decoder.readString() : decoder.readLeftID()) : null, // parent
|
||||||
)
|
cantCopyParentInfo && (info & binary.BIT6) === binary.BIT6 ? decoder.readString() : null, // parentSub
|
||||||
yield struct
|
readItemContent(decoder, info) // item content
|
||||||
clock += struct.length
|
)
|
||||||
} else {
|
yield struct
|
||||||
const len = decoder.readLen()
|
clock += struct.length
|
||||||
yield new GC(createID(client, clock), len)
|
break
|
||||||
clock += len
|
}
|
||||||
|
default: {
|
||||||
|
const len = decoder.readLen()
|
||||||
|
yield new GC(createID(client, clock), len)
|
||||||
|
clock += len
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user