Permalink
Browse files

move compression overhead calcs out of main()

  • Loading branch information...
1 parent 1c64dcf commit e85e4df0efbe6e7e19969c8d5dbec5bdeac5276a discomfitor committed with Aug 11, 2011
Showing with 16 additions and 10 deletions.
  1. +1 −10 main.c
  2. +14 −0 util.c
  3. +1 −0 util.h
View
11 main.c
@@ -540,16 +540,7 @@ int main(int argc, char *argv[])
control->flags &= ~FLAG_UNLIMITED;
}
- /* Work out the compression overhead per compression thread for the
- * compression back-ends that need a lot of ram */
- if (LZMA_COMPRESS) {
- int level = control->compression_level * 7 / 9 ? : 1;
- i64 dictsize = (level <= 5 ? (1 << (level * 2 + 14)) :
- (level == 6 ? (1 << 25) : (1 << 26)));
-
- control->overhead = (dictsize * 23 / 2) + (4 * 1024 * 1024);
- } else if (ZPAQ_COMPRESS)
- control->overhead = 112 * 1024 * 1024;
+ setup_overhead(control);
/* Set the main nice value to half that of the backend threads since
* the rzip stage is usually the rate limiting step */
View
14 util.c
@@ -133,6 +133,20 @@ void failure(const char *format, ...)
fatal_exit();
}
+void setup_overhead(rzip_control *control)
+{
+ /* Work out the compression overhead per compression thread for the
+ * compression back-ends that need a lot of ram */
+ if (LZMA_COMPRESS) {
+ int level = control->compression_level * 7 / 9 ? : 1;
+ i64 dictsize = (level <= 5 ? (1 << (level * 2 + 14)) :
+ (level == 6 ? (1 << 25) : (1 << 26)));
+
+ control->overhead = (dictsize * 23 / 2) + (4 * 1024 * 1024);
+ } else if (ZPAQ_COMPRESS)
+ control->overhead = 112 * 1024 * 1024;
+}
+
void setup_ram(rzip_control *control)
{
/* Use less ram when using STDOUT to store the temporary output file. */
View
1 util.h
@@ -27,6 +27,7 @@ void unlink_files(void);
void register_outputfile(FILE *f);
void fatal(const char *format, ...);
void failure(const char *format, ...);
+void setup_overhead(rzip_control *control);
void setup_ram(rzip_control *control);
void round_to_page(i64 *size);
void get_rand(uchar *buf, int len);

0 comments on commit e85e4df

Please sign in to comment.