@@ -10,8 +10,8 @@ import (
1010// Txn is a transaction against a tree. It allows doing efficient
1111// modifications to a tree by caching and reusing cloned nodes.
1212type Txn [T any ] struct {
13- opts * options
1413 root * header [T ]
14+ opts options
1515 size int // the number of objects in the tree
1616
1717 // mutated is the set of nodes mutated in this transaction
@@ -63,7 +63,7 @@ func (txn *Txn[T]) InsertWatch(key []byte, value T) (old T, hadOld bool, watch <
6363 if ! hadOld {
6464 txn .size ++
6565 }
66- if txn .opts .rootOnlyWatch {
66+ if txn .opts .rootOnlyWatch () {
6767 watch = txn .root .watch
6868 }
6969 return
@@ -88,7 +88,7 @@ func (txn *Txn[T]) ModifyWatch(key []byte, mod func(T) T) (old T, hadOld bool, w
8888 if ! hadOld {
8989 txn .size ++
9090 }
91- if txn .opts .rootOnlyWatch {
91+ if txn .opts .rootOnlyWatch () {
9292 watch = txn .root .watch
9393 }
9494 return
@@ -117,7 +117,7 @@ func (txn *Txn[T]) RootWatch() <-chan struct{} {
117117// value was found.
118118func (txn * Txn [T ]) Get (key []byte ) (T , <- chan struct {}, bool ) {
119119 value , watch , ok := search (txn .root , key )
120- if txn .opts .rootOnlyWatch {
120+ if txn .opts .rootOnlyWatch () {
121121 watch = txn .root .watch
122122 }
123123 return value , watch , ok
@@ -129,7 +129,7 @@ func (txn *Txn[T]) Get(key []byte) (T, <-chan struct{}, bool) {
129129func (txn * Txn [T ]) Prefix (key []byte ) (* Iterator [T ], <- chan struct {}) {
130130 txn .mutated .clear ()
131131 iter , watch := prefixSearch (txn .root , key )
132- if txn .opts .rootOnlyWatch {
132+ if txn .opts .rootOnlyWatch () {
133133 watch = txn .root .watch
134134 }
135135 return iter , watch
@@ -160,7 +160,7 @@ func (txn *Txn[T]) Commit() *Tree[T] {
160160// Tree.Txn().
161161func (txn * Txn [T ]) CommitOnly () * Tree [T ] {
162162 t := & Tree [T ]{opts : txn .opts , root : txn .root , size : txn .size }
163- if ! txn .opts .noCache {
163+ if ! txn .opts .noCache () {
164164 t .txn = txn
165165 }
166166 return t
@@ -188,7 +188,7 @@ func (txn *Txn[T]) cloneNode(n *header[T]) *header[T] {
188188 if n .watch != nil {
189189 txn .watches [n .watch ] = struct {}{}
190190 }
191- n = n .clone (! txn .opts .rootOnlyWatch || n == txn .root )
191+ n = n .clone (! txn .opts .rootOnlyWatch () || n == txn .root )
192192 nodeMutatedSet (txn .mutated , n )
193193 return n
194194}
@@ -225,7 +225,7 @@ func (txn *Txn[T]) modify(root *header[T], key []byte, mod func(T) T) (oldValue
225225 if this .watch != nil {
226226 txn .watches [this .watch ] = struct {}{}
227227 }
228- this = this .promote (! txn .opts .rootOnlyWatch || this == root )
228+ this = this .promote (! txn .opts .rootOnlyWatch () || this == root )
229229 nodeMutatedSet (txn .mutated , this )
230230 } else {
231231 // Node is big enough, clone it so we can mutate it
@@ -298,7 +298,7 @@ func (txn *Txn[T]) modify(root *header[T], key []byte, mod func(T) T) (oldValue
298298 newNode := & node4 [T ]{}
299299 newNode .setPrefix (common )
300300 newNode .setKind (nodeKind4 )
301- if ! txn .opts .rootOnlyWatch {
301+ if ! txn .opts .rootOnlyWatch () {
302302 newNode .watch = make (chan struct {})
303303 }
304304
0 commit comments