mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 16:52:18 +01:00
Fix rac.Writer with more than 510 leaf nodes
This commit is contained in:
1 parent
a1a5b40178
commit
5cfb01a69b
2 files changed
+44
-10
No files matched your search
+25
-10
@@ -21,6 +21,13 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func btoi(b bool) int {
|
||||||
|
if b {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
func isZeroOrAPowerOf2(x uint64) bool {
|
func isZeroOrAPowerOf2(x uint64) bool {
|
||||||
return (x & (x - 1)) == 0
|
return (x & (x - 1)) == 0
|
||||||
}
|
}
|
||||||
@@ -656,16 +663,16 @@ func gather(nodes []node) node {
|
|||||||
for ; j < len(nodes); j++ {
|
for ; j < len(nodes); j++ {
|
||||||
o := &nodes[j]
|
o := &nodes[j]
|
||||||
|
|
||||||
arity++
|
new2 := (o.secondary != 0) && !resources[o.secondary]
|
||||||
if (o.secondary != 0) && !resources[o.secondary] {
|
new3 := (o.tertiary != 0) && !resources[o.tertiary]
|
||||||
resources[o.secondary] = true
|
arity += 1 + btoi(new2) + btoi(new3)
|
||||||
arity++
|
|
||||||
}
|
|
||||||
if (o.tertiary != 0) && !resources[o.tertiary] {
|
|
||||||
resources[o.tertiary] = true
|
|
||||||
arity++
|
|
||||||
}
|
|
||||||
if arity <= 0xFF {
|
if arity <= 0xFF {
|
||||||
|
if new2 {
|
||||||
|
resources[o.secondary] = true
|
||||||
|
}
|
||||||
|
if new3 {
|
||||||
|
resources[o.tertiary] = true
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -675,7 +682,15 @@ func gather(nodes []node) node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
i = j
|
i = j
|
||||||
arity = 0
|
arity = 1
|
||||||
|
if o.secondary != 0 {
|
||||||
|
resources[o.secondary] = true
|
||||||
|
arity++
|
||||||
|
}
|
||||||
|
if o.tertiary != 0 {
|
||||||
|
resources[o.tertiary] = true
|
||||||
|
arity++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
|
|||||||
@@ -319,3 +319,22 @@ func TestWriterMultiLevelIndex(t *testing.T) {
|
|||||||
t.Fatalf("\ngot:\n%s\nwant:\n%s", got, want)
|
t.Fatalf("\ngot:\n%s\nwant:\n%s", got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWriter1000Chunks(t *testing.T) {
|
||||||
|
w := &Writer{
|
||||||
|
Writer: ioutil.Discard,
|
||||||
|
Codec: fakeCodec,
|
||||||
|
}
|
||||||
|
data := make([]byte, 1)
|
||||||
|
res, _ := w.AddResource(data)
|
||||||
|
for i := 0; i < 1000; i++ {
|
||||||
|
if i == 2*255 {
|
||||||
|
_ = w.AddChunk(1, data, res, 0)
|
||||||
|
} else {
|
||||||
|
_ = w.AddChunk(1, data, 0, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := w.Close(); err != nil {
|
||||||
|
t.Fatalf("Close: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user