:: commit e44014a74ff727f12a9f5ce302aaafec9f664674

Kamila Szewczyk <kspalaiologos@gmail.com> — 2022-05-13 08:59

parents: 926477ccd2

move the call to `flush` to encoding

diff --git a/include/cm.h b/include/cm.h
index 413c954..e97c1e0 100644
--- a/include/cm.h
+++ b/include/cm.h
@@ -16,7 +16,6 @@ typedef struct {
     u16 C0[256], C1[256][256], C2[512][17];
 } state;
 
-void flush(state * s);
 void init(state * s);
 void begin(state * s);
 void encode_bytes(state * s, u8 * c, s32 size);
diff --git a/src/cm.c b/src/cm.c
index 1d1afd4..ef9f395 100644
--- a/src/cm.c
+++ b/src/cm.c
@@ -30,17 +30,6 @@
 #define write_out(s, c) (s)->out_queue[(s)->output_ptr++] = (c)
 #define read_in(s) ((s)->input_ptr < (s)->input_max ? (s)->in_queue[(s)->input_ptr++] : -1)
 
-void flush(state * s) {
-    write_out(s, s->low >> 24);
-    s->low <<= 8;
-    write_out(s, s->low >> 24);
-    s->low <<= 8;
-    write_out(s, s->low >> 24);
-    s->low <<= 8;
-    write_out(s, s->low >> 24);
-    s->low <<= 8;
-}
-
 void init(state * s) {
     s->code = (s->code << 8) + read_in(s);
     s->code = (s->code << 8) + read_in(s);
@@ -127,6 +116,15 @@ void encode_bytes(state * s, u8 * buf, s32 size) {
         s->c2 = s->c1;
         s->c1 = ctx & 255;
     }
+
+    write_out(s, s->low >> 24);
+    s->low <<= 8;
+    write_out(s, s->low >> 24);
+    s->low <<= 8;
+    write_out(s, s->low >> 24);
+    s->low <<= 8;
+    write_out(s, s->low >> 24);
+    s->low <<= 8;
 }
 
 void decode_bytes(state * s, u8 * c, s32 size) {
diff --git a/src/libbz3.c b/src/libbz3.c
index 8fbaf9d..79f5fe9 100644
--- a/src/libbz3.c
+++ b/src/libbz3.c
@@ -165,7 +165,6 @@ PUBLIC_API s32 bz3_encode_block(struct bz3_state * state, u8 * buffer, s32 data_
     state->cm_state->out_queue = b1 + overhead * 4 + 1;
     state->cm_state->output_ptr = 0;
     encode_bytes(state->cm_state, b2, data_size);
-    flush(state->cm_state);
     data_size = state->cm_state->output_ptr;
 
     // Write the header. Starting with common entries.
tab: 248 wrap: offon