trie/bintrie: move ensureWritable into setValue

This commit is contained in:
CPerezz 2026-04-15 22:53:50 +02:00
parent ee951bad21
commit efc164b850
No known key found for this signature in database
GPG key ID: 62045F34B97177DD
2 changed files with 1 additions and 3 deletions

View file

@ -97,6 +97,7 @@ func (sn *StemNode) ensureWritable() {
// setValue sets or inserts a value at the given suffix.
func (sn *StemNode) setValue(suffix byte, value []byte) {
sn.ensureWritable()
idx := int(suffix)
pos := sn.posInData(suffix)
if pos >= 0 {

View file

@ -192,7 +192,6 @@ func (s *NodeStore) InsertSingle(stem []byte, suffix byte, value []byte, resolve
if s.root.Kind() == KindStem {
sn := s.getStem(s.root.Index())
if sn.Stem == [StemSize]byte(stem[:StemSize]) {
sn.ensureWritable()
sn.setValue(suffix, value)
sn.mustRecompute = true
return nil
@ -235,7 +234,6 @@ func (s *NodeStore) insertSingleInternal(stem []byte, suffix byte, value []byte,
case KindStem:
sn := s.getStem(cur.Index())
if sn.Stem == [StemSize]byte(stem[:StemSize]) {
sn.ensureWritable()
sn.setValue(suffix, value)
sn.mustRecompute = true
return nil
@ -432,7 +430,6 @@ func (s *NodeStore) insertValuesAtStem(ref NodeRef, stem []byte, values [][]byte
sn := s.getStem(ref.Index())
if sn.Stem == [StemSize]byte(stem[:StemSize]) {
// Same stem — merge values
sn.ensureWritable()
for i, v := range values {
if v != nil {
sn.setValue(byte(i), v)