]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/common/chunk_size.c
29a8e02bc99afa69715ec8c59cd87b3da21875a9
[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 //  Copyright (C) 2007 Lasse Collin
7 //
8 //  This library is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU Lesser General Public
10 //  License as published by the Free Software Foundation; either
11 //  version 2.1 of the License, or (at your option) any later version.
12 //
13 //  This library is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 //  Lesser General Public License for more details.
17 //
18 ///////////////////////////////////////////////////////////////////////////////
19
20 #include "common.h"
21
22
23 /**
24  * \brief       Finds out the minimal reasonable chunk size for a filter chain
25  *
26  * This function helps determining the Uncompressed Sizes of the Blocks when
27  * doing multi-threaded encoding.
28  *
29  * When compressing a large file on a system having multiple CPUs or CPU
30  * cores, the file can be splitted in smaller chunks, that are compressed
31  * independently into separate Blocks in the same .lzma Stream.
32  *
33  * \return      Minimum reasonable Uncompressed Size of a Block. The
34  *              recommended minimum Uncompressed Size is between this value
35  *              and the value times two.
36
37  Zero if the Uncompressed Sizes of Blocks don't matter
38  */
39 extern LZMA_API(size_t)
40 lzma_chunk_size(const lzma_options_filter *filters)
41 {
42         while (filters->id != LZMA_VLI_UNKNOWN) {
43                 switch (filters->id) {
44                 // TODO LZMA_FILTER_SPARSE
45
46                 case LZMA_FILTER_COPY:
47                 case LZMA_FILTER_SUBBLOCK:
48                 case LZMA_FILTER_X86:
49                 case LZMA_FILTER_POWERPC:
50                 case LZMA_FILTER_IA64:
51                 case LZMA_FILTER_ARM:
52                 case LZMA_FILTER_ARMTHUMB:
53                 case LZMA_FILTER_SPARC:
54                         // These are very fast, thus there is no point in
55                         // splitting the data in smaller blocks.
56                         break;
57
58                 case LZMA_FILTER_LZMA1:
59                         // The block sizes of the possible next filters in
60                         // the chain are irrelevant after the LZMA filter.
61                         return ((lzma_options_lzma *)(filters->options))
62                                         ->dictionary_size;
63
64                 default:
65                         // Unknown filters
66                         return 0;
67                 }
68
69                 ++filters;
70         }
71
72         // Indicate that splitting would be useless.
73         return SIZE_MAX;
74 }