Re: [PATCH] Make zlib compression level configurable, and change default.
- From
Linus Torvalds <torvalds@osdl.org>
- Date
- Jul 3, 2006, 19:33 UTC
- Message-ID
- <Pine.LNX.4.64.0607031226370.12404@g5.osdl.org>
- In-Reply-To
- <85d5cm8qfn.fsf_-_@lupus.ig3.net>
On Mon, 3 Jul 2006, Joachim B Haga wrote:
Show 5 quoted lines
> > The configurability is through setting core.compression = [-1..9] > which maps to the zlib constants; -1 is the default, 0 is no > compression, and 1..9 are various speed/size tradeoffs, 9 > being slowest.
My only worry is that this encodes "Z_DEFAULT_COMPRESSION" as being -1, which happens to be /true/, but I don't think that's a documented interface (you're supposed to use the Z_DEFAULT_COMPRESSION macro, which could have any value, and just _happens_ to be -1).
Is it likely to ever change from that -1? Probably not. So I think your patch is technically correct, but it might just be nicer if it did something like
..
if (!strcmp(var, "core.compression")) {
int level = git_config_int(var, value);
if (level == -1)
level = Z_DEFAULT_COMPRESSION;
else if (level < 0 || level > Z_BEST_COMPRESSION)
die("bad zlib compression level %d", level);
zlib_compression_level = level;
return 0;
}
..which would be safer, and a smart compiler might notice that the -1 case ends up being a no-op, and then just generate code AS IF we just had a
if (level < -1 || level > Z_BEST_COMPRESSION) die(...
there.
Oh, and for all the same reasons, we should use
int zlib_compression_level = Z_BEST_COMPRESSION;
for the default initializer.
Hmm?
Linus