mirror of
https://github.com/vasi/pixz
synced 2024-11-15 00:13:00 +00:00
simpler block queuing; go back to dict_size blocks; run test in bash, some sh have no "time"
This commit is contained in:
parent
8a90a6dce7
commit
c158b057f2
2
test.sh
2
test.sh
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
#base=lmnopuz
|
#base=lmnopuz
|
||||||
#file=lmnopuz/CheckPUZ.app/Contents/Resources/script
|
#file=lmnopuz/CheckPUZ.app/Contents/Resources/script
|
||||||
|
58
write.c
58
write.c
@ -58,7 +58,8 @@ static archive_close_callback tar_ok;
|
|||||||
|
|
||||||
static void block_init(lzma_block *block);
|
static void block_init(lzma_block *block);
|
||||||
static void stream_edge(lzma_vli backward_size);
|
static void stream_edge(lzma_vli backward_size);
|
||||||
static void write_blocks(io_block_t **ibs, size_t *seq);
|
static void write_blocks(size_t *seq, io_block_t **ibs, io_block_t *ib);
|
||||||
|
static void write_block(io_block_t *ib);
|
||||||
static void encode_index(void);
|
static void encode_index(void);
|
||||||
|
|
||||||
static void write_file_index(void);
|
static void write_file_index(void);
|
||||||
@ -84,7 +85,7 @@ int main(int argc, char **argv) {
|
|||||||
.options = &lzma_opts };
|
.options = &lzma_opts };
|
||||||
gFilters[1] = (lzma_filter){ .id = LZMA_VLI_UNKNOWN, .options = NULL };
|
gFilters[1] = (lzma_filter){ .id = LZMA_VLI_UNKNOWN, .options = NULL };
|
||||||
|
|
||||||
gBlockInSize = lzma_opts.dict_size * 2.0;
|
gBlockInSize = lzma_opts.dict_size * 1.0;
|
||||||
gBlockOutSize = lzma_block_buffer_bound(gBlockInSize);
|
gBlockOutSize = lzma_block_buffer_bound(gBlockInSize);
|
||||||
|
|
||||||
// thread setup
|
// thread setup
|
||||||
@ -121,9 +122,7 @@ int main(int argc, char **argv) {
|
|||||||
if (msg == MSG_STOP)
|
if (msg == MSG_STOP)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
ib->next = ibs;
|
write_blocks(&seq, &ibs, ib);
|
||||||
ibs = ib;
|
|
||||||
write_blocks(&ibs, &seq);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// file index
|
// file index
|
||||||
@ -321,38 +320,43 @@ static void stream_edge(lzma_vli backward_size) {
|
|||||||
die("Error writing stream edge");
|
die("Error writing stream edge");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_blocks(io_block_t **ibs, size_t *seq) {
|
static void write_block(io_block_t *ib) {
|
||||||
// check if we can write anything
|
// Does it make sense to chunk this?
|
||||||
bool block_missing = false;
|
size_t written = 0;
|
||||||
while (!block_missing) {
|
while (ib->outsize > written) {
|
||||||
block_missing = true; // assume no match
|
size_t size = ib->outsize - written;
|
||||||
|
if (size > CHUNKSIZE)
|
||||||
io_block_t *prev = NULL;
|
size = CHUNKSIZE;
|
||||||
for (io_block_t *ib = *ibs; ib; ib = ib->next) {
|
if (fwrite(ib->output + written, size, 1, gOutFile) != 1)
|
||||||
if (ib->seq == *seq) { // we have the next block
|
|
||||||
if (fwrite(ib->output, ib->outsize, 1, gOutFile) != 1)
|
|
||||||
die("Error writing block data");
|
die("Error writing block data");
|
||||||
|
written += size;
|
||||||
|
}
|
||||||
|
|
||||||
if (lzma_index_append(gIndex, NULL,
|
if (lzma_index_append(gIndex, NULL,
|
||||||
lzma_block_unpadded_size(&ib->block),
|
lzma_block_unpadded_size(&ib->block),
|
||||||
ib->block.uncompressed_size) != LZMA_OK)
|
ib->block.uncompressed_size) != LZMA_OK)
|
||||||
die("Error adding to index");
|
die("Error adding to index");
|
||||||
|
}
|
||||||
|
|
||||||
// remove the found block
|
static void write_blocks(size_t *seq, io_block_t **ibs, io_block_t *ib) {
|
||||||
if (prev) {
|
// insert it into the queue, in order
|
||||||
prev->next = ib->next;
|
io_block_t **prev = ibs, *post = *ibs;
|
||||||
} else {
|
while (post && post->seq < ib->seq) {
|
||||||
*ibs = ib->next;
|
prev = &post->next;
|
||||||
|
post = post->next;
|
||||||
}
|
}
|
||||||
queue_push(gReadQ, MSG_BLOCK, ib);
|
ib->next = post;
|
||||||
|
*prev = ib;
|
||||||
|
|
||||||
|
// write the blocks that we can
|
||||||
|
io_block_t *cur = *ibs;
|
||||||
|
while (cur && cur->seq == *seq) {
|
||||||
|
write_block(cur);
|
||||||
|
queue_push(gReadQ, MSG_BLOCK, cur);
|
||||||
++*seq;
|
++*seq;
|
||||||
block_missing = false;
|
cur = cur->next;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
*ibs = cur;
|
||||||
prev = ib;
|
|
||||||
} // for io_block_t
|
|
||||||
} // while !block_missing
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void encode_index(void) {
|
static void encode_index(void) {
|
||||||
|
Loading…
Reference in New Issue
Block a user