When placing a Lazy(Array|Object) into the tree, copy its [ptr, len] into the parent...
authorNick Downing <nick@ndcode.org>
Thu, 6 Jan 2022 23:24:56 +0000 (10:24 +1100)
committerNick Downing <nick@ndcode.org>
Thu, 6 Jan 2022 23:24:56 +0000 (10:24 +1100)
logjson.mjs

index 522e27d..d78a7f5 100644 (file)
@@ -212,7 +212,8 @@ class Transaction {
     this.dirty = true
     if (typeof value === 'object' && value !== null) {
       assert(value instanceof Lazy && value.transaction === this)
-      value = [-1, 0, value]
+      let [ptr, len] = value.ptr_len || [-1, 0]
+      value = [ptr, len, value]
     }
     this.value = value
   }
@@ -350,7 +351,8 @@ class LazyArray extends Lazy {
     this.ptr_len = null // mark dirty
     if (typeof value === 'object' && value !== null) {
       assert(value instanceof Lazy && value.transaction === this.transaction)
-      value = [-1, 0, value]
+      let [ptr, len] = value.ptr_len || [-1, 0]
+      value = [ptr, len, value]
     }
     this.array[key] = value
     this.length = this.array.length
@@ -445,7 +447,8 @@ class LazyObject extends Lazy {
     this.ptr_len = null // mark dirty
     if (typeof value === 'object' && value !== null) {
       assert(value instanceof Lazy && value.transaction === this.transaction)
-      value = [-1, 0, value]
+      let [ptr, len] = value.ptr_len || [-1, 0]
+      value = [ptr, len, value]
     }
     this.object[key] = value
   }