]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/common/chunk_size.c
Put the interesting parts of XZ Utils into the public domain.
[icculus/xz.git] / src / liblzma / common / chunk_size.c
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       chunk_size.c
4 /// \brief      Finds out the minimal reasonable chunk size for a filter chain
5 //
6 //  Author:     Lasse Collin
7 //
8 //  This file has been put into the public domain.
9 //  You can do whatever you want with this file.
10 //
11 ///////////////////////////////////////////////////////////////////////////////
12
13 #include "common.h"
14
15
16 /**
17  * \brief       Finds out the minimal reasonable chunk size for a filter chain
18  *
19  * This function helps determining the Uncompressed Sizes of the Blocks when
20  * doing multi-threaded encoding.
21  *
22  * When compressing a large file on a system having multiple CPUs or CPU
23  * cores, the file can be splitted in smaller chunks, that are compressed
24  * independently into separate Blocks in the same .lzma Stream.
25  *
26  * \return      Minimum reasonable Uncompressed Size of a Block. The
27  *              recommended minimum Uncompressed Size is between this value
28  *              and the value times two.
29
30  Zero if the Uncompressed Sizes of Blocks don't matter
31  */
32 extern LZMA_API(size_t)
33 lzma_chunk_size(const lzma_options_filter *filters)
34 {
35         while (filters->id != LZMA_VLI_UNKNOWN) {
36                 switch (filters->id) {
37                 // TODO LZMA_FILTER_SPARSE
38
39                 case LZMA_FILTER_COPY:
40                 case LZMA_FILTER_SUBBLOCK:
41                 case LZMA_FILTER_X86:
42                 case LZMA_FILTER_POWERPC:
43                 case LZMA_FILTER_IA64:
44                 case LZMA_FILTER_ARM:
45                 case LZMA_FILTER_ARMTHUMB:
46                 case LZMA_FILTER_SPARC:
47                         // These are very fast, thus there is no point in
48                         // splitting the data in smaller blocks.
49                         break;
50
51                 case LZMA_FILTER_LZMA1:
52                         // The block sizes of the possible next filters in
53                         // the chain are irrelevant after the LZMA filter.
54                         return ((lzma_options_lzma *)(filters->options))
55                                         ->dictionary_size;
56
57                 default:
58                         // Unknown filters
59                         return 0;
60                 }
61
62                 ++filters;
63         }
64
65         // Indicate that splitting would be useless.
66         return SIZE_MAX;
67 }