1
0
mirror of https://github.com/chylex/Brotli-Builder.git synced 2025-04-07 00:15:50 +02:00

Simplify context map construction

This commit is contained in:
chylex 2020-04-12 09:55:37 +02:00
parent eee5f88be7
commit 435b9d8e5b
2 changed files with 11 additions and 5 deletions
BrotliLib/Brotli
Components/Header
Encode/Build

View File

@ -24,10 +24,10 @@ namespace BrotliLib.Brotli.Components.Header{
private readonly byte[] contextMap;
public ContextMap(Category category, int treeCount, byte[] contextMap){
this.Category = category;
this.TreeCount = treeCount;
public ContextMap(Category category, byte[] contextMap){
this.contextMap = CollectionHelper.Clone(contextMap);
this.Category = category;
this.TreeCount = 1 + contextMap.Max();
this.ContextsPerBlockType = category.Contexts();
}
@ -290,7 +290,13 @@ namespace BrotliLib.Brotli.Components.Header{
}
}
return new ContextMap(category, treeCount, contextMap);
var constructed = new ContextMap(category, contextMap);
if (constructed.TreeCount != treeCount){
throw new InvalidOperationException("Calculated context map tree count does not match the serialized number (" + constructed.TreeCount + " != " + treeCount + ").");
}
return constructed;
}
);

View File

@ -135,7 +135,7 @@ namespace BrotliLib.Brotli.Encode.Build{
}
public ContextMap Build(){
return new ContextMap(category, TreeCount, contextMap);
return new ContextMap(category, contextMap);
}
}
}